Original address: Http://docs.pythontab.com/python/python3.4/datastructures.html#tut-tuples
The best way to understand a dictionary is to think of it as an unordered key: a set of value pairs (Key:value pairs) whose keys must be distinct (within the same dictionary).
A pair of curly braces creates an empty dictionary: {} .
>>> Tel = {'Jack': 4098,'Sape': 4139}>>> tel['Guido'] = 4127>>>tel{'Sape': 4139,'Guido': 4127,'Jack': 4098}>>> tel['Jack']4098>>>deltel['Sape']>>> tel['Irv'] = 4127>>>tel{'Guido': 4127,'Irv': 4127,'Jack': 4098}>>>list (Tel.keys ()) ['Irv','Guido','Jack']>>>Sorted (Tel.keys ()) ['Guido','Irv','Jack']>>>'Guido' inchteltrue>>>'Jack' not inchTelfalse
The dict () constructor can create a dictionary directly from the Key-value pair:
>>> dict ('sape', 4139), ('Guido', 4127), (' Jack', 4098)] {'sape'Jack 'Guido': 4127}
In addition, the dictionary derivation can create a dictionary from any of the key-value expressions:
for inch (2, 4, 6)} {2:4, 4:16, 6:36}
If the keyword is a simple string, it is sometimes more convenient to specify Key-value by keyword arguments:
>>> dict (sape=4139, guido=4127, jack=4098) {'sape'Jack 'Guido': 4127}
Python Data Structures-dictionaries