Python Dictionary
kodingwindow@kw:~$ python3
...
>>> KV={'s1':'Linus','s2':'Thomson','s3':'Edison'}
>>> KV
{'s3': 'Edison', 's2': 'Thomson', 's1': 'Linus'}

>>> KV['s2']
'Thomson'

>>> len(KV)
3

>>> max(KV)
's3'

>>> min(KV)
's1'

>>> Dict=KV.copy()
>>> Dict
{'s1': 'Linus', 's2': 'Thomson', 's3': 'Edison'}

>>> KV['s4']='Neil'
>>> KV
{'s3': 'Edison', 's2': 'Thomson', 's1': 'Linus', 's4': 'Neil'}

>>> KV.update(s5='John')
>>> KV
{'s1': 'Linus', 's2': 'Thomson', 's3': 'Edison', 's4': 'Neil', 's5': 'John'}

>>> del KV['s5']
>>> KV
{'s1': 'Linus', 's2': 'Thomson', 's3': 'Edison', 's4': 'Neil'}

>>> KV.keys()
dict_keys(['s1', 's2', 's3', 's4'])

>>> KV.values()
dict_values(['Linus', 'Thomson', 'Edison', 'Neil'])

>>> KV.items()
dict_items([('s1', 'Linus'), ('s2', 'Thomson'), ('s3', 'Edison'), ('s4', 'Neil')])

>>> for(a,b) in KV.items():
...     print(b,a)
... 
Linus s1
Thomson s2
Edison s3
Neil s4

>>> for(a) in KV.values():
...     print(a)
... 
Linus
Thomson
Edison
Neil

>>> KV.clear()
>>> KV
{}
What Next?
Python Arrays
Advertisement