Pages

Python: Dictionaries

There is a cool feature in Python which is called 'dictionary'. And as it sounds it is same as the dictionary. When we search for a word in dictionary we find the related explaination. The dictionary in Python works like this too.

dict = {'red' : 'color of blood' , 'car' : 'vehicle on the streets' , 'flow' : 'continuity'}
print dict

Let's print flow:

print dict['flow']

We can add more words to our dicitonary.

dict['python'] = 'Montly Python\' s Flying Circus'
print dict

We can use numbers too:

dict[1] = 'one'
dict[5] = 'five'
print dict

If we want to delete a member:

del dict['red']
del dict['1']
print dict