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

george hart gehart24 at
Sat Jan 4 04:42:51 CET 2003


My problem is that I have a very complex data structure I need to
iterate over and change certain values to.  I wrote a 'generator' to
iterate over my data structure but when i call the next() method in
the generator object I am returned a value that cannot be used to
modifiy the original data structure.

Here is a simplified version of my problem:

def generator(l):
    for i in l:
        if type(i) is list:
            for q in generator(i):
                yield q
            yield i

o=100   # where i want this assignment to change a[0] to 100
print a[0]  #thus a[0] would then print out 100

Thanks for any help,

More information about the Python-list mailing list