dict1 = {'a':1,'b':2} new_dict1 = {} for k,v in dict1.items(): # items() 函数以列表返回可遍历的(键, 值) 元组数组。 new_dict1[k] = v #给新字典赋值(键,对) print(new_dict1)
python,循环遍历字典并赋给一个新字典
最新推荐文章于 2024-05-27 17:01:21 发布
dict1 = {'a':1,'b':2} new_dict1 = {} for k,v in dict1.items(): # items() 函数以列表返回可遍历的(键, 值) 元组数组。 new_dict1[k] = v #给新字典赋值(键,对) print(new_dict1)