我怎样才能比较两个OrderedDict dictionareis?
我的结构如下:
dict_a = OrderedDict([(1,4), (2,5), (3,3), (4,5), (5,4), (6,4), (7,4), (8,3), (9,4)])
dict_b = OrderedDict([(1,4), (2,2), (3,1), (4,4), (5,6), (6,7), (7,4), (8,2), (9,5)])
for values in score_dict.items():
if values == course_dict.values():
print 'match!'
else:
print 'No match!'
Run Code Online (Sandbox Code Playgroud)
它迭代通过,两个列表都是有序的,所以它应该匹配1和7?提前致谢!
Sim*_*ser 11
您可以使用items()和内置zip()功能:
for i, j in zip(dict_a.items(), dict_b.items()):
if i == j:
print(i)
Run Code Online (Sandbox Code Playgroud)
输出:
(1, 4)
(7, 4)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5740 次 |
| 最近记录: |