我有两大类词典,看起来类似于:
array1(下面代码中的errat1):
[{'advisory_name': 'CL-SA-2016:0071', 'advisory_type': 'Security Advisory', 'issue_date': '2016-01-26 21:00:00', 'advisory': 'CL-SA-2016:0071'}]
数组2的结构类似:(下面代码中的errat2)
[{'advisory_name': 'CL-SA-2016:2098', 'advisory_type': 'Security Advisory', 'issue_date': '2016-10-23 21:00:00', 'advisory': 'CL-SA-2016:2098'}]
如果事实上字典中有更多的项目
我从API
获取上述数组我的代码如下:
chnnls = client.channel.listMyChannels(key)
for chnnl in chnnls:
if valid_label1(chnnl['label']): #this is regex function to limit the dictionary items to errat1 items only
errat1 = client.channel.software.listErrata(key, chnnl['label'])
if valid_label2(chnnl['label']): #this is regex function to limit the dictionary items to errat2 items only
errat2 = client.channel.software.listErrata(key, chnnl['label'])
matches = []
errat_indexed = {}
for item in errat1:
errat_indexed[(item["advisory_name"])] = item
for item in errata2:
if not (item["advisory_name"]) in errat_indexed:
matches.append(item)
for only in matches:
print only['advisory_name']
我的目标是比较2个字典arrata1和errata2只用于' advisory_name'的值。 ,只获取' advisory_name'的值。只退出errata2数组字典。我的代码没有给我脚本中的Amy结果输出。
答案 0 :(得分:0)
首先,制作出现在set
中的advisory_name
的{{1}},然后浏览errata1
并根据该集检查名称。
errata2