PEP 276 -- What else could iter(5) mean?
Bernhard Herzog
bh at intevation.de
Wed Mar 6 16:37:29 EST 2002
James_Althoff at i2.com writes:
> [huaiyu]
> > "spam".append("eggs")
> > x, y, z = "d"
> > x, y, z = 3
> > [f(x) for x in (4 in 3) in (2 in 3) if x in (x+1 in x*2)] # just for fun.
> :-)
>
> Fun? Ok, if you say so.
>
> But just to make sure I understand your point, I guess you are saying the
> above is bad because today's equivalent is more clear?
>
> [f(x) for x in range((4 in range(3))) in range((2 in range(3))) if x in
> range((x+1 in range(x*2)))]
That's not quite right, I think :)
[f(x)
for x in range((4 in range(3)) in range((2 in range(3))))
if x in range((x+1 in range(x*2)))]
would me more like it (but it's late so there may still be a mistake :) )
Anyway, I think that booleans will be iterable too could be problematic.
OTOH, that they're ints could be considered problematic too but hasn't
actually been a problem AFAICT.
> Can you suggest a less contrived example that might be a problem?
x, = 1
would assign 0 to x instead of raising an error.
Bernhard
--
Intevation GmbH http://intevation.de/
Sketch http://sketch.sourceforge.net/
MapIt! http://mapit.de/
More information about the Python-list
mailing list