8.8) Dictionary Methods
Here are some useful dictionary methods.
The list of dictionary keys is obtained with:
>>> a.keys()
The list of values is obtained with:
>>> a.values()
You can also test whether a dictionary has an element with a specific key, such as 'Name':
>>> a.has_key('Name')
For example:
>>> Bilbo={'Name':['Bilbo','Baggins'], 'Race':'Elf', 'Gender':'Male', 'DoB':[22,'September',2890]} >>> Bilbo.keys() ['DoB', 'Gender', 'Race', 'Name'] >>> Bilbo.values() [[22, 'September', 2890], 'Male', 'Elf', ['Bilbo', 'Baggins']] >>> Bilbo.has_key('Name') True