list comprehensions value assignment syntax error
Neal Norwitz
neal at metaslash.com
Tue Jan 7 19:34:42 EST 2003
On Tue, 07 Jan 2003 14:18:22 -0500, Gerrit Holl wrote:
> Hi,
>
> I am trying to assign to a list item using list comprehensions, but this
> raises a SyntaxError:
>
>>>> [l[i] = chr(i) for i in range(256)]
> File "<stdin>", line 1
> [l[i] = chr(i) for i in range(256)]
> ^
> SyntaxError: invalid syntax
I don't understand what you are trying to do.
If you want to create a list of characters 1..256 (or 10)
since it fits on one line :-)
>>> [chr(i) for i in range(10)]
['\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t']
Neal
More information about the Python-list
mailing list