1 def f(d): 2 return d.keys() 3 4 def g(d): 5 for key, value in d.items(): 6 return value 7 8 d = {10 : "a", 20 : "b"} 9 print d[10] # a 10 print d[20] # b 11 try: 12 print d[30] # should fail with an exception 13 except KeyError, exc: 14 print "d[30]: key not found", exc.key 15 16 l = f(d) 17 print l 18 print 10 in l # True 19 print 20 in l # True 20 print 30 in l # False 21 22 l = d.values() 23 print l 24 print "a" in l # True 25 print "b" in l # True 26 print "c" in l # False 27 28 v = g(d) # either "a" or "b" 29 print v 30 print v == "a" or v == "b" # True 31 print v == 10 or v == 20 # False 32 33 l = d.items() 34 print l 35 print (10, "a") in l # True 36 print (10, "b") in l # False