On 9/23/05, Nick Coghlan <ncoghlan at gmail.com> 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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4