list comprehensions value assignment syntax error

Neal Norwitz neal at
Wed Jan 8 01:34:42 CET 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']


More information about the Python-list mailing list