Python - Dictionary's Key Value items
代码
>>> DictTest={"key1":"value1","key2":"value2","key3":"value3"}
>>> DictTest
{'key3': 'value3', 'key2': 'value2', 'key1': 'value1'}
>>> DictTest.keys()
['key3', 'key2', 'key1']
>>> DictTest.values()
['value3', 'value2', 'value1']
>>> DictTest.items()
[('key3', 'value3'), ('key2', 'value2'), ('key1', 'value1')]
Notes:
- The keys method of a dictionary returns a list of all the keys. The list is not in the order in which the dictionary was defined (remember that elements in a dictionary are unordered), but it is a list.
- The values method returns a list of all the values. The list is in the same order as the list returned by keys, so params.values()[n] == params[params.keys()[n]] for all values of n.
- The items method returns a list of tuples of the form (key, value). The list contains all the data in the dictionary.
Work for fun,Live for love!