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

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -