get keys with the same values

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Jun 12 07:35:48 EDT 2008


Nader:
> d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' : 4)}
> I will something as :
> d.keys(where their values are the same)

That's magic.


> With this statement I can get two lists for this example:
> l1= ['a','e']
> l2=['b','d']
> Would somebody tell me how I can do it?

You can create a new dict where the keys are the values of the input
dict and the values are a list of the keys of the original dict. So
scanning the keys, values of the input dict, you can fill the second
dict. Then you can scan the second dict, and create a list that
contains only value lists longer than one.

Bye,
bearophile



More information about the Python-list mailing list