压缩并分配:
for d, d['content'] in zip(dicts, contents):
pass
演示(
Try it online!
):
import pprint
dicts = [{'url': 'https://test.com/find/city-1', 'tit': 'title1', 'val': 1},
{'url': 'https://test.com/find/city-2', 'tit': 'title1', 'val': 2},
{'url': 'https://test.com/find/city-3', 'tit': 'title1', 'val': 3}
]
contents = ['a','b','c']
for d, d['content'] in zip(dicts, contents):
pass
pprint.pp(dicts)
输出:
[{'url': 'https://test.com/find/city-1',
'tit': 'title1',
'val': 1,
'content': 'a'},
{'url': 'https://test.com/find/city-2',
'tit': 'title1',
'val': 2,
'content': 'b'},
{'url': 'https://test.com/find/city-3',
'tit': 'title1',
'val': 3,
'content': 'c'}]