【发布时间】:2017-10-13 08:10:38
【问题描述】:
我对非常简单的两阶段字典有疑问。 我的字典在值中有键(数字)、第二键(数字)和名称公司。 我只需要检查 1 号键,因为我知道“福特”名称出现的唯一可能性是字典 [i][1] 正如您所看到的 - 字符串与键 100% 不相等。键可以包含“Ford”(但键中有另一个部件名称:“Ford Motor”),因此如果每个 Dictionary[i][1] 中出现“Ford” - 将此键分配给空字典“MATCHINGITEMS”按顺序:
matchingitems[1] = "Ford"
matchingitems[2] = "Ford" etc
你能帮帮我吗?
Dictionary = { „1” : { „1” : "Ford Motor",
„2” : "Volkswagen Autos"
}
"2" : { "1" : "Ducati",
"2" : "Yamaha"
}
"3" : { "1" : "Ford",
"2" : "SEAT"
}
}
matchingitems = {}
i = 0
for value in Dictionary.items():
for key in Dictionary.items[value]:
i += 1
if "Ford" in Dictionary[i][1]:
matchingitems[i] = "Ford"
【问题讨论】:
标签: python dictionary nested