我想知道如何在字典中找到重复的值并返回包含这些值的键。
下面是一个例子:
d = {'happy':['sun', 'moon', 'chocolate'], 'sad':['fail', 'test', 'bills'], 'random': ['baloon', 'france', 'sun'] }
如您所见,键的happy和random具有相同/重复的值,即“sun”,因此我要的输出是:
random, happy
我真的不明白我怎么能找到那样的重复值。
如果我有一个特定的值,比如“Chocolate”,那么我可以使用d.keys()简单地执行for循环。。。
如果您使用的是Python 3,那么应该输出一个包含任何重复项的元组:
给出:
超快速和肮脏
在定义形式上:(你应该经常这样做)
然后你就可以这样玩了
相关问题 更多 >
编程相关推荐