loop over list and modify in place

Paul Rubin http
Sat Sep 30 19:47:45 EDT 2006


"Daniel Nogradi" <nogradi at gmail.com> writes:
> 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'

for m in mylist:
   m.newattribute = 'new value'



More information about the Python-list mailing list