filter() and booleanness

rihad rihad at mail.ru
Sun Jan 20 07:24:12 EST 2002


Hi there, the following two calls will both print ('hi', 'there') due
to None being substituted for `identity function' (as the docs say):

print filter(None, ('hi', None, 0, 'there'))
print filter(lambda x: x, ('hi', None, 0, 'there'))

Then I thought I'd clamp the x to [0..1] but things like x != 0 missed
None and x != None missed 0. :) Now I have lambda x: not not x, is it
bulletproof? (it seems to work).

TIA




More information about the Python-list mailing list