CISC 121 Chapter Notes - Chapter 11: Local Variable, Global Variable
![CISC 121 Full Course Notes](https://new-docs-thumbs.oneclass.com/doc_thumbnails/list_view/2588659-class-notes-ca-queens-cisc-121-lecture32.jpg)
35
CISC 121 Full Course Notes
Verified Note
35 documents
Document Summary
Like a list but more general: indices can be almost any type, for dictionaries indices = keys, making a dictionary. Eng2sp = dict( : reprint dictionary, key order is unpredictable, if you use a key not in the dictionary you get an exception eng2sp, adding to a dictionary. Keyerror: (cid:494)four(cid:495: len( ) returns the number of key-value pairs, the in operator can say if there is a key present not a value. To see if a value is present: Use x =dictionary. values( ) which returns a collection of all values. Then use the in operator for x. List: time taken directly correlates to number of items. Dictionary as a collection of counters: def histogram(s): d = dict( ) for c in s: if c not in d: d[c] = 1 else: d[c] += 1 return d. Reverse lookup: lookup: value = dictionary[key] Finding a value using a key: reverse lookup. Value may be assigned to multiple keys.