Dictionary 如果某些值重复,如何从字典中删除键

Dictionary 如果某些值重复,如何从字典中删除键,dictionary,parsing,Dictionary,Parsing,我有一个数据集,其中包含有关已运行作业的一些详细信息。看起来是这样的: { "1": [ "infra", "failed", "toby" ], "2": [ "staging", "failed", "james&qu

我有一个数据集,其中包含有关已运行作业的一些详细信息。看起来是这样的:

{
    "1": [
        "infra",
        "failed",
        "toby"
        ],
    "2": [
        "staging",
        "failed",
        "james"
        ],
    "3": [
        "dev",
        "finished",
        "tommy"
        ],
    "4": [
        "infra",
        "failed",
        "peter"
        ],
    "5": [
        "dev",
        "failed",
        "toby"
        ]
}
{
    "1": [
        "infra",
        "failed",
        "toby"
        ],
    "2": [
        "staging",
        "failed",
        "james"
        ],
    "3": [
        "dev",
        "finished",
        "tommy"
        ]
}
如何筛选出共享一些任意值的键,在本例中是第一个值和第二个值?这将从文件的开头一直到结尾,因此它最终看起来像这样:

{
    "1": [
        "infra",
        "failed",
        "toby"
        ],
    "2": [
        "staging",
        "failed",
        "james"
        ],
    "3": [
        "dev",
        "finished",
        "tommy"
        ],
    "4": [
        "infra",
        "failed",
        "peter"
        ],
    "5": [
        "dev",
        "failed",
        "toby"
        ]
}
{
    "1": [
        "infra",
        "failed",
        "toby"
        ],
    "2": [
        "staging",
        "failed",
        "james"
        ],
    "3": [
        "dev",
        "finished",
        "tommy"
        ]
}

请注意,筛选前后键的顺序必须相同。

请将您尝试过的代码张贴出来。我很难决定哪些应该被淘汰,以及为什么。如果您为此编写一个函数,可能会更容易。顺序在dict中并不重要——我们可以让它在python3中以特定的顺序显示,但如果这很重要,您应该真正使用collections.OrderedDict。或者在本例中,列表比dict更好(因为键只是索引)