Dictionaries
Creating a dictionary
# empty dictionary
myDict = {}
print (myDict)
# dictionary with integer keys
myDict = {1: 'apple', 2: 'ball'}
print( myDict)
# dictionary with mixed keys
myDict = {'name': 'John', 1: [2, 4, 3]}
print (myDict)
# using dict()
myDict = dict({1:'apple', 2:'ball'})
print (myDict)
# from sequence having each item as a pair
myDict = dict([(1,'apple'), (2,'ball')])
print (myDict)Accessing Elements
Change or Add Elements
Delete Elements
Traversing a Dictionary
Merging Dictionaries
Other Dictionary Methods
len(s)
dict.clear()
dict.get(key[, value])
dict.has_key(key)
dict.items()
dict.keys()
dict.values()
Last updated