Re:Python does support if-else in lambdas...
by myelin on Sunday November 09, 2008 @11:39PM
(#358873)
The danger here is that this will fall through to the falseaction if trueaction returns a false result ("", False, 0, None, [], {}, etc). For example, this will evaluate to "etc":
So people started doing this instead, as [False] is still 'true' (non-empty lists are 'true' in Python):
... which is a bit crufty. So this was added:
[ Parent
| on HN ]
Re:Python does support if-else in lambdas...
by thomasmallen on Sunday November 09, 2008 @11:42PM
(#358880)
Ah, that is much better. I've been learning from Dive Into Python which I know is a tad dated, and Pilgrim (sort of) endorses the and...or method.