python - Find keys for values that appear more than once -


i have dictionary follows:

mydict ={1:'apple',2:'banana',3:'banana',4:'apple',5:'mango'} 

i want compute list contains keys values appear more once:

mylist = [1,2,3,4] 

value 'mango' appears once, , therefore key 5 not present in mylist.

how can achieve this?

you can use counter this:

>>> collections import counter  >>> c = counter(mydict.values()) >>> [k k, v in mydict.items() if c[v] > 1] [1, 2, 3, 4] 

Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -