loop over list and modify in place

Paul Rubin http
Sun Oct 1 01:47:45 CEST 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