Py学习  »  Python

如何使用列表在python中添加新键和值?[闭门]

user12217822 • 3 年前 • 1395 次点击  

我有一本字典和一份清单。 我想向字典中添加一个新键,这样每个键的值都等于一个数组元素。我在下面的例子中对此做了更多解释

我的字典

[{'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}
]

我的名单

['a','b','c']

我想要的是:

[{'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'}
]
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/128610
 
1395 次点击  
文章 [ 2 ]  |  最新文章 3 年前