# W6_Lists - Announcements CSCA08H Week 6 more lists A2...

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

CSCA08H Week 6 more list s 1 Announcements A2 coming very soon (today ?) 2 2 Today: Questions? collections, lists, indeces 3 3 ? Questions? 4 4

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

View Full Document
Collections Why can we go through a string in a for loop? It is a collection of characters Sometimes, we want to collect (group) other things, too: temperature over the last 20 days rainfall people's names and ages . . . 5 5 Strings are collections of characters We may want to "collect" other things, too: rainfall, shoe sizes, meal prices, names, - you name it, we can collect it and keep it! 6 Lists 7 list: an ordered collection of "things": rainfall measurements: 22.3, 23.2, 45.0 rain_1 = 22.3 rain_2 = 23.2 rain_3 = 45.0 . . . rain_119 = 0.3 Nah! - keep it all in one place. 7 Lists Keep the values in a list: rain = [22.3, 23.2, 45.0] An ordered collection: each element has a position, we refer to it as its index First index is 0 Refer to the ±rst element as rain[0] second as rain[1] , etc. Just like strings 8 8
Lists may contain anything: strings, booleans, Pixels, fles.… best_friend = "Nicole" friends = ["Mumtaz","Indira", best_friend, "Mary"] A list may contain values oF diFFerent types: grab_bag = ["Michael", 23.9, -5, False, [1, 2]] Lists have methods: Friends.append(), Friends.remove(), …. Friends.upper()??? NO (why?) Lists are a data type 9 9 Lists are ordered and indexed Again, just like strings instructors = ['Cathy', 'Diane', 'Dan', \ 'Michelle', 'Steve', 'Michael']

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/26/2011 for the course CS a48 taught by Professor Michael during the Fall '10 term at University of Toronto.

### Page1 / 8

W6_Lists - Announcements CSCA08H Week 6 more lists A2...

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

View Full Document
Ask a homework question - tutors are online