Bruno Desthuilliers wrote: > Sam Pointon a écrit : > > Bruno Desthuilliers wrote: > > > >>foo = lambda thing: thing and thing + 1 or -1 > > > > > > The and ... or trick is buggy (what if thing == -1?) > > Yes, true - Should be: > foo2 = lambda t: t != -1 and (t and t+1 or -1) or 0 > Actually, the common work-around for this is:
(thing and [thing+1] or [-1])[0] This works since non-empty lists are always considered true in conditional context. This is more generic, and IMO more readable. -- http://mail.python.org/mailman/listinfo/python-list