小编Fat*_*teh的帖子

将列表值应用于字典列表

假设我有一个字典列表,如下所示:

final_list = [{'city': 'value', 'population': 'value'}, {'city': 'value', 'population': 'value'}, {'city': 'value', 'population': 'value'}]
Run Code Online (Sandbox Code Playgroud)

我有一个看起来像这样的列表:

input_list = [['London', 'New York', 'San Francisco'], [8908081, 8398748, 883305]]
Run Code Online (Sandbox Code Playgroud)

我想正确的价值观,从地图input_listfinal_list,但我无法弄清楚如何。我想它会是这样的:

n = 0 
while n < len(final_list):
     for category in input_list:
          for section in final_list:
                # then here, somehow say 
                # for the nth item in each of the sections, update the value to nth item in category
                # then increment n
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激!提前致谢 :)

python list-comprehension dictionary-comprehension

2
推荐指数
1
解决办法
57
查看次数