python 字典操作

创建字典
arr = {'one':{'o':'123'},'two':{'t':'to'}}

arr.setdefault('one',{'omg':'o my gud'}) #查看字段是否存在,不存在就创建字典


b = {
'two':{'t':'to'},
'three' : {'h':'ee'}
}

arr.update(b) #将两个数组数据合并,去掉两个数组间重复的字典

arr.items() #将字典转成列表

c = dict.fromkeys([6,7,8])
print(c) #创建一个新的字典,


for k,v in arr.items(): #arr.items()将字典转成列表,循环将列表的数据遍历


列表生成式
[i*2 for i in range(10)]

原文地址:https://www.cnblogs.com/jasonLiu2018/p/10733386.html