list of lists, object doesn't support item assignment?

Steffen Ries steffen.ries at sympatico.ca
Fri Jun 29 08:12:55 EDT 2001


Manfred Bartz <mdadd329ea at xix.com> writes:

> >>> 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?

You are using tuples instead of lists. Tuples are immutable, i.e. you
can't assign new elements to an existing one. To use lists do the
following:

xy = [[1,2], [2,2]]
xy[1] = [3,4]
print xy
xy[1][0] = 5
print xy

/steffen
-- 
steffen.ries at sympatico.ca	<> Gravity is a myth -- the Earth sucks!



More information about the Python-list mailing list