The dictionaries in Python are completely different. They are not sequences, they are not ordered, but a ing. The internal elements are separated by commas (,).
. They are stored through keys instead of locations. They are also changeable and can be changed, increased, or decreased locally.
Main attributes:
<1> Read data by key instead of offset
<2> unordered set of any object
<3> variable length, heterogeneous, and arbitrary nesting
<4> variable ing
<5> Object Reference Table
Common Operations
D = {} empty dictionary
'Name' in D member existence Test
D. keys () method: Key
D. values () Value
D. items () Key + Value
D. copy () copy
D. get (key, default) default
D. update (D1) Merge
D. pop (key) Deletion
Len (D) evaluate the length
D [name] = 'ww 'modify and add
Del D [key] Delete
List (D. values () list (D. items () list (D. keys () converts the value to list
Ing operation
>>> D = {}
>>> D ['name'] = 'bob'
>>> D ['job'] = 'dev'
>>> D ['age'] = 40
>>> D
{'Age': 40, 'job': 'dev', 'name': 'bob '}
>>> Print (D ['name'])
Bob
Traversal
Since there is no order, we can first convert the dictionary key to list, sort and print.
>>> D = list (D. keys ())
>>> D
['A', 'C', 'B']
>>> D. sort ()
>>> D
['A', 'B', 'C']
>>> For I in d:
Print (I, '=>', d [I])
A => 1
B => 2
C => 3
Simplified point
>>> For key in sorted (D ):
Print (key, '=>', D [key])
Usage notes:
<1> the sequence operation is invalid (no sequence)
<2> assign a value to the new index to add an item.
<3> keys are not always strings.
<4> avoid missing key errors
Reference < >