0

我正在使用 Python 2.7.4。我正在尝试比较 python 中两个不同字典的值,并根据比较结果构建一个新字典。我的用户将马的帖子位置和 mlodds1 和 tbodds1 输入到 3 个列表中,然后我执行以下操作:

ml_dict = dict(zip(postpositions,mlodds1))
tb_dict = dict(zip(postpositions,tbodds1))

从这些列表中构造两个字典。我想要一本新字典:screened_dict[a,x]由 tb_dict[a,x] 和 ml_dict(a, y) 中的值 x < y 组成。提前致谢。

4

1 回答 1

0
combined = {}
for x in ml_dict:
    try:
        if tb_dict[x] < ml_dict[x]: combined[x] = ml_dict[x]
    except KeyError: continue
于 2013-05-20T14:38:53.133 回答