Dictionaries are sets where each element (a key) has associated an object (a value). In fact, sets can be seen as dictionaries where the elments have not associations. As sets, dictionaries are efficient for indexing by keys.
In [ ]:
help({})
In [ ]:
a = {'Macinstosh':'OSX', 'PC':'Windows', 'Macintosh-Linux':'Linux', 'PC-Linux':'Linux'}
a
In [ ]:
a['PC']
In [ ]:
'PC-Linux' in a
In [ ]:
a.keys()
In [ ]:
a.values()
In [ ]:
list(a.keys()).index("Macintosh-Linux")
In [ ]:
for i in a.keys():
print(i)
In [ ]:
a['Celullar'] = "Android"
a
In [ ]:
del a['Celullar']
a
In [ ]:
# Modifiying an entry
a.update({"PC": "Windows 10"})
a
In [ ]:
id(a)
In [ ]:
a['Macintosh-Linux'] = 'Linux for the Mac'
a
In [ ]:
id(a)
In [ ]:
for i in a:
print(i, a[i])
In [ ]:
for i in a.values():
print(i)
In [ ]:
for i in a.items():
print(i)