【发布时间】:2018-01-15 22:34:44
【问题描述】:
我有两个像这样的list:
first_list=[{
'a': 2,
'c': '[53, 94, 58]'
},
{
'a': 3,
'c': '[81, 43, 38]'
}]
和
second_list=[{
"d" : 2,
"e" : "name_two",
"f":True
},
{
"d" : 3,
"e" : "name_three",
"f":False
}]
我怎样才能创建这个'dict':
{"name_two": [53, 94, 58],
"name_three": [53, 94, 58]}
并将其添加到另一个dict,如下所示:
{
"x" : {
"foo":some_values
"name_two":[53, 94, 58]
"name_three":[81, 43, 38]
}
"y" : ["name_two","name_two"]
}
【问题讨论】:
-
How can I create this 'dict'... 好问题,你有什么办法来回答它? -
'x'、'y'和some_values是如何以编程方式生成的? x 的键是否始终是 first_list 中字典中键'e'的值?构建应该很容易 - 它正在弄清楚这里的困难逻辑!
标签: python list dictionary