Python-3.5匹配dicts列表中的值以组合2

时间:2017-03-27 21:42:05

标签: python dictionary python-3.5

我是Python的新手,并且在将我的需求列表组合在一起时遇到问题。它们正在适当地压缩,但正如你所看到的那样,它实际上并不是我需要它们的顺序。这些是动态列表,以下两个是示例。

列表1:data_keys:

[{'id': 438, 'title': "Route from 'GetCallerDetail' to 'GreetingDefault'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}, 
{'id': 441,'title': "Route from 'DNISGreeting' to 'HOOCheck'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}, 
{'id': 440, 'title': "Route from 'GreetingDefault' to 'HOOCheck'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}, 
{'id': 436, 'title': "Route from 'Start' to 'GetCallerDetail'", 'pre_conditions': [], 'tc_steps': [{'expected': '', 'content': 'APN: 8552929487, HollyBrowser: , '}]}, 
{'id': 439, 'title': "Route from 'GetCallerDetail' to 'DNISGreeting'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}]

列出2 network_edges:

[{'to': 4891, 'id': 441, 'from': 4890}, {'to': 4888, 'id': 436, 'from': 4887}, {'to': 4889, 'id': 438, 'from': 4888}, {'to': 4891, 'id': 440, 'from': 4889}, {'to': 4890, 'id': 439, 'from': 4888}]

我的zip代码:

for d, n in zip(network_edges, data_keys):
    d['data'] = n

当前输出:

[{'from': 4890, 'id': 441, 'data': [{'title': "Route from 'GetCallerDetail' to 'GreetingDefault'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}], 'to': 4891}, 
{'from': 4887, 'id': 436, 'data': [{'title': "Route from 'DNISGreeting' to 'HOOCheck'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}], 'to': 4888}, 
{'from': 4888, 'id': 438, 'data': [{'title': "Route from 'GreetingDefault' to 'HOOCheck'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}], 'to': 4889}, 
{'from': 4889, 'id': 440, 'data': [{'title': "Route from 'Start' to 'GetCallerDetail'", 'tc_steps': [{'expected': '', 'content': 'APN: 8552929487, HollyBrowser: , '}], 'pre_conditions': []}], 'to': 4891}, 
{'from': 4888, 'id': 439, 'data': [{'title': "Route from 'GetCallerDetail' to 'DNISGreeting'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}], 'to': 4890}]

我需要什么:

[{'from': 4890, 'id': 441, 'data': [{'title': "Route from 'DNISGreeting' to 'HOOCheck'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}], 'to': 4891}, 
{'from': 4887, 'id': 436, 'data': [{'title': "Route from 'Start' to 'GetCallerDetail'", 'tc_steps': [{'expected': '', 'content': 'APN: 8552929487, HollyBrowser: , '}], 'pre_conditions': []}], 'to': 4888}, 
{'from': 4888, 'id': 438, 'data': [{'title': "Route from 'GetCallerDetail' to 'GreetingDefault'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}], 'to': 4889}, 
{'from': 4889, 'id': 440, 'data': [{'title': "Route from 'GreetingDefault' to 'HOOCheck'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}], 'to': 4891}, 
{'from': 4888, 'id': 439, 'data': [{'title': "Route from 'GetCallerDetail' to 'DNISGreeting'", 'tcs_cannot_route': "This edge cannot be routed: MenuPrompt/MenuPromptWC property 'Outputs' not found"}], 'to': 4890}]

让自己划过眼睛,因为他们似乎正确排队,但事实并非如此。感谢您的指导。基本上来自'来自'是我需要与"标题'中的字符串名称匹配的关键值。如果为了简单起见,我会在这些内容中添加更多内容,如果没有必要,我宁愿不让它们陷入困境。

0 个答案:

没有答案