loop over list and modify in place

Daniel Nogradi nogradi at gmail.com
Sat Sep 30 13:45:24 EDT 2006


Is looping over a list of objects and modifying (adding an attribute
to) each item only possible like this?

mylist = [ obj1, obj2, obj3 ]

for i in xrange( len( mylist ) ):
    mylist[i].newattribute = 'new value'


I'm guessing there is a way to do this without introducing the (in
principle unnecessary) index i, so what I'm really looking for is a
looping method which doesn't pass references to the values of the
items but to the items themselves.



More information about the Python-list mailing list