{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec-11-9 - Announcements Program 5 due tomorrow No class...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
11/9/2009 1 ECS 10 11/9 Announcements Program 5 due tomorrow. No class Wednesday (Veteran’s day). Midterm review Friday. Midterm 2 Monday Midterm 2 Monday. Today – when to use what data structure, and a bit about how dictionaries work. Lists shopping = [“milk”, “eggs”, “tea”] print shopping[2] Items in a list are stored in order. Look up an item by its position. A list is always indexed by integers, starting with zero. An index which is >= the length of the list causes an error. Dictionaries Values in a dictionary are indexed by keys, which can be anything. Items in a dictionary are not in any particular order. Looking up a key that is not in the dictionary causes an error; check first: if “sparrow” in petDict: print petDict[“sparrow”] for loop with a list shopping = [“milk”, “eggs”, “tea”] for product in shopping: print “We’re out of”,product Variable product takes on the values of each of Variable product takes on the values of each of the items in the list in turn. Block under the for statement is executed three times. No index variable. for loop with a dictionary for pet in petDict: print pet,petDict[pet] In the first line the variable pet becomes on
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}