# dictionary # A dictionalry is used to save unique key-value pairs. It uses curly brackets. a = {} # create an empty dictionary named a b = {"state": "CA", "zip": 94301} # create a dictionary named b that holds two key-value pairs "state": "CA" and "zip": 94301 print a # prints {} print b # prints {"state": "CA", "zip": 94301} # accessing the value of a key: print b["state"] # print out the value of the key "state". It prints "CA" # replace the value of a key: b["state"] = "NY" # replace the value of the key "state". The new value should be "NY" print b["state"] # # prints out the new value of the key "state". It prints "NY" # add a new key-value pair at the beginning of the dictionary: b["newkey"] = "new value" # add a new key-value pair whereas the key should be named "newkey" and its value "new value" print b["newkey"] # It prints "new value" # delete a key-value pair from a dictionary: del b["state"] print b # it prints {"newkey":"new value", "zip": 94301} # looping through all keys and values in the dictionary: for key, value in b.items(): print "KEY: ", key, "VALUE: ", value # prints out all keys and their values of the dictionary. # It prints KEY: newkey VALUE: new value and in next line KEY: zip VALUE: 94301