In [14]:
>>> tell = {'jack' : 4098, 'sape' :4139}
>>> tell['guido'] = 4127
>>> tell


Out[14]:
{'guido': 4127, 'jack': 4098, 'sape': 4139}

In [15]:
>>> tell['jack']


Out[15]:
4098

In [16]:
>>> del tell['sape']
>>> tell


Out[16]:
{'guido': 4127, 'jack': 4098}

In [17]:
>>> tell['ivy'] = 4127
>>> tell


Out[17]:
{'guido': 4127, 'ivy': 4127, 'jack': 4098}

In [19]:
>>> tell['brek'] = 4128
>>> tell


Out[19]:
{'brek': 4128, 'guido': 4127, 'ivy': 4127, 'jack': 4098}

In [20]:
>>> list(tell.keys())


Out[20]:
['ivy', 'jack', 'brek', 'guido']

In [21]:
>>> sorted(tell.keys())


Out[21]:
['brek', 'guido', 'ivy', 'jack']

In [22]:
>>> 'guido' in tell


Out[22]:
True

In [23]:
>>> 'hello' in tell


Out[23]:
False

In [27]:
>>> dict([('jakc',4089),('sape',4139),('ivy',4438)])


Out[27]:
{'ivy': 4438, 'jakc': 4089, 'sape': 4139}

In [28]:
>>> {x:x**2 for x in (2,4,6)}


Out[28]:
{2: 4, 4: 16, 6: 36}

In [29]:
>>> dict(brek=4128,guido=4127,sape=4098)


Out[29]:
{'brek': 4128, 'guido': 4127, 'sape': 4098}

In [38]:
>>> knights = {'gallahand':'the pure','Robin':'the brave'}
>>> for k,v in knights.items():
    print(k,v)


Robin the brave
gallahand the pure

In [40]:
>>> for i,v in enumerate (['tic','tac','toe']):
    print (i,v)


0 tic
1 tac
2 toe

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))


what is yourname? it is Charlie.
what is yourage? it is 23.
what is yourcolor? it is blue.

In [50]:
>>> for i in reversed(range(1,10,3)):
>>>     print(i)


7
4
1

In [52]:
>>> basket = ['apple','banana','orange','passionfruit','coconut']
>>> for f in sorted(set(basket)):
        print(f,end=' ')


apple banana coconut orange passionfruit 

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]:
['defenestrate', 'cat', 'window', 'defenestrate']

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]:
True

In [ ]:


In [ ]: