In [14]:
>>> tell = {'jack' : 4098, 'sape' :4139}
>>> tell['guido'] = 4127
>>> tell
Out[14]:
In [15]:
>>> tell['jack']
Out[15]:
In [16]:
>>> del tell['sape']
>>> tell
Out[16]:
In [17]:
>>> tell['ivy'] = 4127
>>> tell
Out[17]:
In [19]:
>>> tell['brek'] = 4128
>>> tell
Out[19]:
In [20]:
>>> list(tell.keys())
Out[20]:
In [21]:
>>> sorted(tell.keys())
Out[21]:
In [22]:
>>> 'guido' in tell
Out[22]:
In [23]:
>>> 'hello' in tell
Out[23]:
In [27]:
>>> dict([('jakc',4089),('sape',4139),('ivy',4438)])
Out[27]:
In [28]:
>>> {x:x**2 for x in (2,4,6)}
Out[28]:
In [29]:
>>> dict(brek=4128,guido=4127,sape=4098)
Out[29]:
In [38]:
>>> knights = {'gallahand':'the pure','Robin':'the brave'}
>>> for k,v in knights.items():
print(k,v)
In [40]:
>>> for i,v in enumerate (['tic','tac','toe']):
print (i,v)
In [44]:
>>> questions = ['name','age','color']
>>> answers = ['Charlie','23','blue']
>>> for i,v in zip(questions,answers):
print('what is your{0}? it is {1}.'.format(i,v))
In [50]:
>>> for i in reversed(range(1,10,3)):
>>> print(i)
In [52]:
>>> basket = ['apple','banana','orange','passionfruit','coconut']
>>> for f in sorted(set(basket)):
print(f,end=' ')
In [1]:
>>> words = ['cat', 'window', 'defenestrate']
>>> for w in words[:]: # Loop over a slice copy of the entire list.
... if len(w) > 6:
... words.insert(0, w)
...
>>> words
Out[1]:
In [3]:
(1, 2, 3) < (1, 2, 4)
[1, 2, 3] < [1, 2, 4]
'ABC' < 'C' < 'Pascal' < 'Python'
(1, 2, 3, 4) < (1, 2, 4)
(1, 2) < (1, 2, -1)
(1, 2, 3) == (1.0, 2.0, 3.0)
(1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)
Out[3]:
In [ ]:
In [ ]: