loop over list and modify in place

Daniel Nogradi nogradi at gmail.com
Sat Sep 30 13:59:39 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.

Please consider the previous question as an arbitrary random brain
cell fluctuation whose probability of occurence is around once per
month and before sending the question it hasn't yet happened to me in
September.



More information about the Python-list mailing list