CECS 174 Lecture Notes - Lecture 8: Anthony Giacalone, Mike Trout, Yasiel Puig
Document Summary
# a "dictionary" is a "data structure" -- a way of organizing many values into. A list is another type of data structure. # typically allow us to add, remove, and find values in them. # of a list are associated with a position (an integer index), values of a. # a python dictionary is denoted with { }, similar to a list denoted with [ ]. # instead of individual values separated by commas, we give a list of. The "key" of each pair is something easy to remember, # through which the dictionary can provide access to the associated value. # to retrieve a value, we "index" the dictionary with the associated key. print("neal"s phone number is " + contacts["neal terrell"]) print("mehrdad"s phone number is " + contacts["mehrdad aliasgari"]) # keys have to match exactly; it is a run-time error (semantic error) to index. # a dictionary with a key that does not exist.