On 9/23/05, Nick Coghlan <[EMAIL PROTECTED]> wrote: > But I think there's a difference in kind here - to *fix* Raymond's example > required a fundamental change to the structure of the line, none of which > looked as clean as the original. There is no way to get the and/or construct > to gracefully handle the case where the desired result in the 'true' case > might itself be false: either you change to using an if statement, or you use > a workaround like the ugly singleton-list approach. > > That is, the following is fundamentally broken for pure imaginary numbers: > return isinstance(z, ComplexType) and z.real or z
It's hard to say whether this fixes Raymond's example when the goal wasn't clearly stated, but I find a non ternary option lambda z: complex(z).real more readable than any of the variants proposed so far. The obvious downsides are that it can raise a ValueError, and turns integers into floats. But if the input list is all numeric, it has clean results. -- Michael Urman _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com