Dictionaries

Dictionaries are string-indexed arrays. Section 15.4.2 shows how these data types are used.

 
#!/usr/bin/env python
hsh = {}                   # create empty dicionary
tel = {'jack': 4098, 'sape': 4139}
tel['guido'] = 4127
print( tel)                  # -> {'sape': 4139, 'guido': 4127, 'jack': 4098}
print( tel['jack'])          # -> 4098
del tel['sape']
tel['irv'] = 4127
print( tel)                  # -> {'guido': 4127, 'irv': 4127, 'jack': 4098}
print( tel.keys())           # -> ['jack', 'irv', 'guido']
print( tel.has_key('guido')) # -> True
print( 'guido' in tel)       # -> True



Subsections