News for hackers. Stuff that matters.
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":

  True and "" or "etc"
So people started doing this instead, as [False] is still 'true' (non-empty lists are 'true' in Python):

  (condition and [trueaction] or [falseaction])[0]
... which is a bit crufty. So this was added:

  trueaction if condition else falseaction
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.