CISC 121 Chapter Notes - Chapter 11: Local Variable, Global Variable

61 views2 pages
wunch and 39345 others unlocked
CISC 121 Full Course Notes
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.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents