You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Dictionaries (Mutable)>>> dict >>> d.items() # this is a view dict_items[(‘alex’,26), ‘(bill’,99), (‘tammy’,35)]Immutable types are hashable, mutable types are not:>>> {} # empty dictionary >>> d.keys() ) # this is a view{} dict_keys[‘alex’, ‘bill’, ‘tammy’]>>> d = {‘john’:23, ‘alex’:25, ‘bill’:99} >>> d.values() # this is a view>>> d = dict(abba=1, dada=2)>>> d[‘alex’] dict_values[26, 99, 35]>>> d[frozenset({1, 2, 3})] = 325 >>> d>>> for x, y in d.items():>>> d[‘alex’] {‘abba’:1, = 26 ‘dada’:2, frozenset({1, >>> 2, … 3}):3} print (x, y)>>> del d[‘john’] ‘alex’ 26>>> d[‘tammy’] >>> d[{1, = 35 2, 3, 4}] = 4 ‘bill’ 99>>> d Traceback (most recent call last): ‘tammy’ 35{‘alex’:26, ‘bill’:99, File "", ‘tammy’:35} line 1, in >>> d.keys() | [‘alex’, ‘john’] # set ops.>>> for key TypeError: in d: unhashable type: 'set’ {‘alex’, ‘bill’, ‘john’, ‘tammy’}>>> … print(key, end = ‘ ‘) >>> d[‘mary’] = 10‘alex’ ‘bill’ ‘tammy’>>> d.keys()dict_keys[‘alex’, ‘bill’, ‘tammy’, ‘mary’]24