list of lists, object doesn't support item assignment?
Delaney, Timothy
tdelaney at avaya.com
Fri Jun 29 00:57:07 EDT 2001
> >>> xy = (1,2),(2,2)
> >>> print xy, xy[0]
> ((1, 2), (2, 2)) (1, 2)
> >>> xy[1]=(3,4)
> TypeError: object doesn't support item assignment
>
> Is there a way to assign the list (3,4) to an element of xy?
> What am I missing?
Quite simple: (1,2) or 1,2 is not a list, but a tuple. Tuples are immutable.
Lists are created with square backets. Try this:
xy = [(1,2),(2,2)]
print xy, xy[0]
xy[1] = (3,4)
Tim Delaney
More information about the Python-list
mailing list