# 108HL15 - Mutability and List Examples Lecture 15 Week 5...

This preview shows pages 1–9. Sign up to view the full content.

Mutability and List Examples Lecture 15, Week 5 February 11, 2011 CSC108H1S Velian Pandeliev 1 Friday, February 11, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Announcements 2 Quiz 2 average was 52% !" !\$ % \$ " ' (% )*+, ( )*+, \$ )*+, - )*+, " Friday, February 11, 2011
About Quiz 2 3 Quiz 2 was the frst time you had to write code From scratch on paper in a time-pressured situation. Wednesday's midterm is going to be like that, except longer. Today's lecture is the last one For which you're responsible on Wednesday. Monday's class will be a review class. Please post to the Discussion Board in topic "Velian's Midterm Review Questions" with topics you would like us to go over. Friday, February 11, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Recap of Lecture 14 Friday, February 11, 2011
List Methods 5 Lists, like strings, have a wide variety of useful methods. Using a list called lst : lst.index(item) - returns the index of the Frst time item appears in lst lst.count(item) - returns the number of times item appears in lst lst.insert(index, item) - inserts item before position index in lst lst.remove(item) - removes the frst occurrence of item from lst Friday, February 11, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
List Methods 6 lst.append(item) - adds item to the end of lst lst.pop(index) - removes and returns the item at index . If index is not supplied, removes and returns the last item in lst lst.extend(anotherlist) - adds all the items in anotherlist to the end of lst lst.reverse() - reverses the order of items in lst lst.sort() - sorts the items in lst in alphanumeric order Friday, February 11, 2011
7 List Examples Friday, February 11, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Total Length 8 def total_length(L):
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/25/2011 for the course CSC 108 taught by Professor Gries during the Spring '08 term at University of Toronto.

### Page1 / 25

108HL15 - Mutability and List Examples Lecture 15 Week 5...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online