The characteristics of a dictionary in Python:
The elements in the dictionary are hash-stored, without order,
Use the keyword (key) that is required in the dictionary when you are checking for additional deletions.
One: Create a dictionary
1) define directly one:
Dict = {' Ob1 ': ' Computer ', ' ob2 ': ' Mouse ', ' ob3 ': ' Printer '}
Note:
The dictionary can contain lists: dict={' yangrong ': [' ['] ', ' IT '], ' xiaohei ': ['] ', ' DotA '}
Dictionary can contain dictionary: dict={' yangrong ': {"Age": "" "," "Job": "IT"}, "Xiaohei": {"' Age ': ' '", ' job ': ' DotA '}}
2) Use Dict to generate one:
>>> name = (' Zhang ', ' lii ', ' ('), ' (' Yubo ', '), (' Zhangyou ', 9))
>>> dic = dict (name)
>>> DIC
{' zhangyou ': 9, ' lii ': +, ' Zhang ':, ' Yuybo ': 92}
3) Use the Zip method to merge two equal-length lists into one dict:
>>> a = ' www.baidu.com.cn.123 '
>>> a_list = A.split ('. ')
>>> a_list
[' www ', ' Baidu ', ' com ', ' cn ', ' 123 ']
>>> b_list = [' 163 ', ' com ', ' vedio ', ' oa ', ' B ']
>>> AA = dict (Zip (a_list,b_list))
>>> AA
{' Baidu ': ' com ', ' www ': ' 163 ', ' 123 ': ' B ', ' com ': ' vedio ', ' cn ': ' OA '}
The a_list list is a keyword straight in the new dictionary, while the B_list list is straight in the new dictionary.
2. Get
3. References and copies
4. Insert (update), delete
CC = {' QQ ': ' qq.com '}
>>> cc
{' QQ ': ' qq.com '}
>>> aa.update (CC)
>>> AA
{' Baidu ': ' com ', ' QQ ': ' qq.com ', ' www ': ' 163 ', ' 123 ': ' B ', ' CN ': ' OA ', ' com ': ' Vedio '}
5. Sorting
Reference: http://www.centoscn.com/python/2014/0318/2598.html
Use of dictionaries in Python