首页 > 解决方案 > 返回所有出现多次且具有不同值的键?

问题描述

所以我有 :

dictionary = {"John:"Legend","Ariana":"Grande", "Sam":"Smith",Ariana":"Smith","Lewis":"Capaldi","John":"Smith"}

所以在这里我想在列表中返回“Ariana”和“John”,因为它们都多次作为键出现,但每次都有不同的值。

到目前为止,我有:

for key in dictionary:
        authors.append(key)
duplicates = []
    for key in dictionary:
        if key not in duplicates:
            duplicates.append(key) # this is to find all the duplicate keys

到目前为止这是正确的吗?我从这里去哪里?

标签: pythondictionary

解决方案


推荐阅读