What is Python dictionary?

If you don’t want to refer to the elements of a collection by their position number but prefer some other type of object as a key,

use a python dictionary

———–

e.g.,

>>> tel = {'jack': 4098, 'sape': 4139}

>>> tel['guido'] = 4127

>>> tel

{'sape': 4139, 'guido': 4127, 'jack': 4098}

>>> tel['jack']

4098

>>> del tel['sape']

>>> tel['irv'] = 4127

>>> tel

{'guido': 4127, 'irv': 4127, 'jack': 4098}

>>> tel.keys()

['guido', 'irv', 'jack']

>>> 'guido' in tel

True

Leave a comment