python data structure - dictionary, a collection of

Compared to lists and tuples, dictionaries of better performance, especially regarding the search, add, and delete operations, the dictionary can be completed within a constant time complexity.

The dictionary and set substantially the same, the only difference is that there is no set paired keys and values ​​of a series of random, unique combination of elements.

1. Create a dictionary and a collection of

d1 = {'name': 'jason', 'age': 20, 'gender': 'male'}
d2 = dict({'name': 'jason', 'age': 20, 'gender': 'male'})
d3 = dict([('name', 'jason'), ('age', 20), ('gender', 'male')])
d4 = dict(name='jason', age=20, gender='male') 
d1 == d2 == d3 ==d4
True

s1 = {1, 2, 3}
s2 = set([1, 2, 3])
s1 == s2
True

2.

Guess you like

Origin www.cnblogs.com/zhaikunkun/p/12634031.html