[Tutor] Problems changing a list item in place ?
Andy W
toodles@yifan.net
Tue, 12 Feb 2002 01:16:54 +0800
> Hello all,
> I have a program with a two-dimensional list called map. After it has
already been populated, I want to do this:
>
> map[y_box][x_box][0] = selected_tile
>
> But I get this error:
>
> File "map_edit.py", line 270, in main
> map[y_box][x_box][0] = selected_tile # Change
value of the tile
> TypeError: object doesn't support item assignment
Could it be that map[y_box][x_box] is referring to a tuple?
Tuples are immutable, so do not support item assignment.
If you make it so that the tuple is a list, then things should work.
Maybe I'm wrong though?
>
> y_box and x_box are indexes; the statement "print map[y_box][x_box]"
works fine. selected_tile is just an integer, though it shouldn't matter.
>
> I thought you could change list items in-place by assignment. Are
multi-dimensional lists different?
>
> Thanks in advance,
> Chris
>
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>