Foreword
Dictionary of CRUD we have some knowledge and understanding of the matter, but the dictionary can also be nested lists, dictionaries, tuples, and other data structures.
First, the dictionary's nest
1, modify, add,
dic = { "name": ["linlin", "小龙", "硬币哥"], "remove": { "addr": "深圳", "time": "2019.4.25", }, "avage": "18", } dic['] = 22 'open# Change = 22 is avage DIC [ ' name ' ] .append ( ' Day ' ) # add name corresponding to the day List Print (DIC)
2, was added to the nested dict dict
dic = { "name": ["linlin", "小龙", "硬币哥"], "remove": { "addr": "深圳", "time": "2019.4.25", }, "avage": "18", } dic["remove"]["man " ] =. 6 # Add man: 6 to remove the dict in Print (DIC [ " remove " ])
3, an example: name change list index 0 corresponding to all uppercase
dic = { "name": ["linlin", "小龙", "硬币哥"], "remove": { "addr": "深圳", "time": "2019.4.25", }, "avage": "18", } dic['name'][0] = dic['name'][0].upper() # 改name对应list下标0为全大写 print(dic)
二、int 快速排序(如果面试题没有特殊要求,应该是可以使用的)
1、int 正向排序,原排序不是按照顺序,用sort()即可。
# int 正向排序 li = [1,5,6,2,8,7,9] li.sort() print(li)
2、int 反向排序,sort(reverse=True)
# int 反向排序 li = [1,5,6,2,8,7,9] li.sort(reverse=True) print(li)
3、反转,就像从列表里的尾到头打印回来。
# 反转 li = [1,2,3,4,5,6,7] li.reverse() print(li)
QQ交流群:99941785