【发布时间】:2016-09-30 17:17:53
【问题描述】:
我想修改字典并创建一个列表,其中包含具有修改后值的字典。我试过了:
mylist = []
mydict = {"one": 10, "two": 20, "three": 30}
for i in [111, 222, 333]:
mydict["two"] = i
mylist.append(mydict)
mylist 返回:
[{'three': 30, 'two': 333, 'one': 10}, {'three': 30, 'two': 333, 'one': 10}, {'three': 30, 'two': 333, 'one': 10}]
我希望得到:
[{'three': 30, 'two': 111, 'one': 10}, {'three': 30, 'two': 222, 'one': 10}, {'three': 30, 'two': 333, 'one': 10}]
我该怎么做?
【问题讨论】:
标签: python list dictionary append