[Tutor] creating new dictionary based on membership testing

ski norman at khine.net
Mon Mar 9 17:05:29 CET 2009


thank you all, great feedback.

Sander Sweers wrote:
> 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.
> 
> Greets
> Sander
> 




More information about the Tutor mailing list