[Tutor] creating new dictionary based on membership testing

Sander Sweers sander.sweers at gmail.com
Mon Mar 9 16:52:42 CET 2009

2009/3/9 A.T.Hofkamp <a.t.hofkamp at tue.nl>:
> You can do something like
> [d for d in d1 if d['is_selected'] == False]
> to get your dicts.
> If 'is_selected' is not always present, it gets a bit more complicated, I'll
> leave that as an exercise for the interested reader :)

You would use d.get('is_selected', False) == False.

If nothing is found then .get() will return False instead of None.


More information about the Tutor mailing list