In [89]:
# This is some IPython %magic
%xmode plain
In [90]:
# with initial values
c = {'foo': 'bar', 'baz': 'qux'}
d = dict([('foo', 'bar'), ('baz', 'qux')])
print c
print d
In [91]:
# keys don't have to be strings
z = {
3: 'a',
'lol': {'foo': 'bar'},
None: False,
}
print z
In [92]:
d = {'foo': 'bar'}
d['baz'] = 'qux'
print d
In [93]:
x = {'baz': 'qux'}
d.update(x)
print d
In [94]:
d['foo']
Out[94]:
In [95]:
# undefined values
d['nope']
In [96]:
# case-sensitive
d['FOO']
In [97]:
d.get('nope', 'aha!') # also callable without a default (implies None)
Out[97]:
In [98]:
print d
d.setdefault('nope', 'aha!')
print d
In [99]:
z[None]
Out[99]:
In [100]:
# notice the key order - there is none!
d.keys()
Out[100]:
In [101]:
d.values()
Out[101]:
In [102]:
d.items()
Out[102]:
In [103]:
print d.has_key('foo')
print d.has_key('zzz')
In [104]:
del(d['nope'])
print d
In [105]:
d.clear()
print d