"""求字典中value有重复元素的key,并返回key""" a= {'a':'a','b':'add','c':'asd','d':'dd'} ['b','d'] """第一种实现方法""" b = [] for i in a.values(): if len(set(i)) != len(i): b.append(list(a.keys())[list(a.values()).index(i)]) print(b) """第二种实现方法""" b = [] for k ,v in a.items(): if len(set(v)) != len(v): b.append(k) print(b)
yy面试题
最新推荐文章于 2024-04-15 06:59:15 发布