[Chicago] newbie says HI; needs help
Atul Varma
varmaa at gmail.com
Fri Jan 20 18:34:20 CET 2006
On 1/20/06, Andrew Dudzik <adudzik at gmail.com> wrote:
> What I meant was:
>
> stock = (2,1)[texture in ["flakey","caked"]]
Whoa. Uh, I've been using Python fairly regularly for almost 3 years
and a co-worker had to tell me that this was an index into a tuple for
me to understand it--at first I thought it was some sort of language
construct I'd never encountered before.
The same co-worker told me that he thought it was "clever", but that
if I ever saw him writing code like that, I should shoot him. ;)
Aside from being difficult to read, though, I also think it's a "hack"
in the same way Andrew's original "hack" was, in that it relies on the
fact that the boolean result "False" maps to 0 and "True" maps to 1.
Even if this is defined in the Python language specification, I think
that using a boolean as an integer by using it as an index into a list
(or subtracting it from an integer) is conceptually unclear.
- Atul
More information about the Chicago
mailing list