1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
demodict = {} demodict = {'a':'1', 'b':'2'} demodict = dict(a=1, b=2) demood = OrderedDict()
demodict.get(key) demodict.get(key, default) demodict.keys(), demodict.values(), demodict.items() demodict.iterkeys(), demodict.itervalues(), demodict.iteritems()
demodict[key] = new_value demodict.update(otherdict) demodict.setdefault(key, value)
demodict.pop(key), demodict.popitem() del demodict[key]
>>> "b" in demodict True
demodict.viewitems()
>>> list = [(1,2), (3,4)] >>> list [(1, 2), (3, 4)] >>> dict((x,y) for x,y in list) {1: 2, 3: 4}
|