1# basic dictionary 2 3d = {} 4print(d) 5d[2] = 123 6print(d) 7d = {1:2} 8d[3] = 3 9print(len(d), d[1], d[3]) 10d[1] = 0 11print(len(d), d[1], d[3]) 12print(str(d) == '{1: 0, 3: 3}' or str(d) == '{3: 3, 1: 0}') 13 14x = 1 15while x < 100: 16 d[x] = x 17 x += 1 18print(d[50]) 19 20# equality operator on dicts of different size 21print({} == {1:1}) 22 23# equality operator on dicts of same size but with different keys 24print({1:1} == {2:1}) 25 26# 0 replacing False's item 27d = {} 28d[False] = 'false' 29d[0] = 'zero' 30print(d) 31 32# False replacing 0's item 33d = {} 34d[0] = 'zero' 35d[False] = 'false' 36print(d) 37 38# 1 replacing True's item 39d = {} 40d[True] = 'true' 41d[1] = 'one' 42print(d) 43 44# True replacing 1's item 45d = {} 46d[1] = 'one' 47d[True] = 'true' 48print(d) 49 50# mixed bools and integers 51d = {False:10, True:11, 2:12} 52print(d[0], d[1], d[2]) 53 54# value not found 55try: 56 {}[0] 57except KeyError as er: 58 print('KeyError', er, er.args) 59 60# unsupported unary op 61try: 62 +{} 63except TypeError: 64 print('TypeError') 65 66# unsupported binary op 67try: 68 {} + {} 69except TypeError: 70 print('TypeError') 71