identity = lambda x: x -- a Pythonic idiom?
Erik Max Francis
max at alcyone.com
Sat Nov 17 16:39:14 EST 2001
George Demmy wrote:
> My understanding of Pythonic truth anything other than None, (), [],
> {}, '', and 0 is true. I don't know what mathematical truth is -- got
> a approachable reference for an interested non-mathematician?
When you're using filter, the function you need maps an object to a
truth value, but the identity function maps an object to itself. In
Python this happens to be the same thing, but what you "really mean" is
lambda x: operator.truth(x).
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ Laws are silent in time of war.
\__/ Cicero
Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
An Esperanto reference for English speakers.
More information about the Python-list
mailing list