Help, replacing the actual value from a data strucutre in a iterator

george hart gehart24 at yahoo.com
Sat Jan 4 06:31:06 EST 2003


> o is now bound to 0
> 
> > o=100   # where i want this assignment to change a[0] to 100
> 
> No way.  You are simply rebinding 'o' to a new value.  Just write
> 'a[0] = 100'!

Hi,

I'm sorry, I think my example was not very good.  I can't just write
'a[0]' because the *real* data structure I am working with is very
complex and nested.  It would be more like a[1][10][20][40] etc..

I am a relatively new to python so I am probably trying solve the
problem the way I would in C (it would be nice to have pointers right
now :-).   The returned value from the .next() method appears to be
pointing to the same memory address as the respective element in the
data structure.  It seems logical that there should be an easy way to
modify it.

Plus, there must be a way to do this?  What is the point of being able
use a generator to iterate over a structure if you can't modify any of
the values?


Thanks,

George




More information about the Python-list mailing list