Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] Type "help", "copyright", "credits" or "license" for more information. >>> #dictionaries >>> emissions = {1799:1, 1800:70, 1801: 74, 1902: 215630} >>> emissions {1800: 70, 1801: 74, 1902: 215630, 1799: 1} >>> emissions[1800] # get value associated with key 1800 70 >>> emissions[1801] = 75.4 # update value associated with key 1801 >>> emissions {1800: 70, 1801: 75.400000000000006, 1902: 215630, 1799: 1} >>> # the length is the number of key, item pairs >>> len(emissions) 4 >>> # we can use a for loop to iterate over elements >>> for k in emissions: ... print k,emissions[k] ... 1800 70 1801 75.4 1902 215630 1799 1 >>> # above shows that you are iterating over the keys >>> #methods for dictionaries >>> emissions.keys() [1800, 1801, 1902, 1799] >>> emissions.values() [70, 75.400000000000006, 215630, 1] >>> emissions.items() # the key, value pairs as tuples [(1800, 70), (1801, 75.400000000000006), (1902, 215630), (1799, 1)] >>> emissions.get(1801) 75.400000000000006 >>> emissions.get(2009) # no error! >>> emissions.get(2009,-3) # you can specify value to return if no key -3 >>> #compare to this >>> print emissions[2009] Traceback (most recent call last): File "", line 1, in KeyError: 2009 >>> # get doesn't give you this error >>> # add dict2 contents to dict1: >>> dict1 = {'444-3333':'Dale','111-2222':'Sally'} >>> dict2 = {'456-2345':'Tom','333-4444':'Bill'} >>> dict1.update(dict2) >>> dict1 {'111-2222': 'Sally', '333-4444': 'Bill', '444-3333': 'Dale', '456-2345': 'Tom'} >>> # of course, this leaves dict2 alone >>> dict2 {'333-4444': 'Bill', '456-2345': 'Tom'} >>> # we did some code in the shell here, but >>> # that code is in a neater form in inverted_dict.py >>>