list comprehensions value assignment syntax error

Gerrit Holl gerrit at nl.linux.org
Thu Jan 9 15:34:53 EST 2003


Steve Holden schreef op woensdag  8 januari om 19:17:51 +0000:
> > I hope you can forgive me <w> ;),
> 
> Easily. I take it what you actually wanted was to construct the list using
> the comprehension?

To fill a part of a 2nd dimension:

WRONG:
[self[i][x1] = w for i in range(y1, y2+1)] # statement instead of expression
self[i][y1:y2+1] = w # w is only one item
self[i][y1:y2+1] = w * range(y1, y2+1) # untested, probably possible but ugly,
                                         and only possible for horizontal, not
                                         for vertical changes

RIGHT:
for i in range(y1, y2+1): self[i][x1] = w

yours,
Gerrit.

-- 
Asperger Syndroom - een persoonlijke benadering:
    http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
    http://www.sp.nl/





More information about the Python-list mailing list