recursively change values in list of lists

Maric Michaud maric at aristote.info
Sun Aug 24 10:53:32 EDT 2008


Le Sunday 24 August 2008 16:17:46 Carson Farmer, vous avez écrit :
> Dear list,
>
> I'm sure this is a relatively trivial problem, but I have been unable
> to find any good examples/explanations on how to do this, so here
> goes:
>
> I have multi-polygon object, which is simply a list of polygons, where
> each polygon is a list of lines, where each line is a list of points.
> What I would like to do, is change the x and y values of each point,
> all the while keeping the structure of the lists intact.
>

As you know the structure by advance, this is not a recusive problem :

for polygon in multi :
    for line in polygon :
        for point in line :
                point[0] += x
                point[1] += y


> So in the end, the only thing that should be changed is the values,
> not the lists themselves... clear as mud?
>
> Any hints, and/or suggestions are greatly appreciated,
>
>
> Carson
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
_____________

Maric Michaud



More information about the Python-list mailing list