list vs. tuple named group vs. non-named group
Aug 022009

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
Posted by weboom at 7:18 pm Tagged with: , , ,

Leave a Reply

(required)

(required)

Switch to our mobile site
Top Footer