recursively change values in list of lists

castironpi castironpi at gmail.com
Sun Aug 24 10:46:49 EDT 2008


On Aug 24, 9:17 am, "Carson Farmer" <carson.far... at gmail.com> wrote:
> 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.
>
> 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

I think you would be looking at:

seq3= [[[0,1],[1,2]],[[3,4]]]
[ [ [ setitem( seq1, i0, seq0* 2 ) for i0, seq0 in enumerate( seq1 ) ]
for seq1 in seq2 ] for seq2 in seq3 ]


>>> seq3= [[[0,1],[1,2]],[[3,4]]]
>>> [ [ [ setitem( seq1, i0, seq0* 2 ) for i0, seq0 in enumerate( seq1 ) ] for seq1 in seq2 ] for seq2 in seq3 ]
[[[None, None], [None, None]], [[None, None]]]
>>> seq3
[[[0, 2], [2, 4]], [[6, 8]]]



More information about the Python-list mailing list