Simple question about mutable container iterator

Neal D. Becker ndbecker2 at verizon.net
Thu Apr 22 09:48:14 EDT 2004


x = [1,2,3]

for i in x:
  i = 2

This doesn't change x.  2 questions:

1) Why not?  Why doesn't assign to an iterator of a mutable type change the
underlying object?

2) What is the preferred way to do this?





More information about the Python-list mailing list