Help, replacing the actual value from a data strucutre in a iterator
Simon Burton
simonb at webone.com.au
Sat Jan 4 07:33:59 EST 2003
On Sat, 04 Jan 2003 03:31:06 +0000, george hart wrote:
>> 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 hear ya
>
> 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 :-).
maybe.
> 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.
two 'pointers' point to the same guy; one pointer cannot influence the
other.
>
> 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?
>
yes, good question. Let us know when you work it out; last time i tried this i
used a tuple (1,10,20,40) to index the offending element, that was before
iterators/generators. at first glance it seems a custom class supporting the
iterator protocol is needed.
>
> Thanks,
>
> George
see you,
Simon Burton
More information about the Python-list
mailing list