I need to extract those keys of a dictionary whose values pass a certain condition. Basically, I want to do this, only in a shorter, more pythony way:
keys=[]
for key in dict:
if dict[key]==True:
keys.append(key)
This was my original idea, but it raises a ValueError:
[key for (key,val) in map if val==True]
I came up with this for the moment, but I can't help feeling it's not very nice:
[key for key in map.keys() if map[key]==True]
Is there a less messy way to it? Perhaps something obvious that I'm clearly missing?
Thanks!