recursively change values in list of lists

C

Carson Farmer

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
 
T

twyk

I see no recursion in the problem as stated. Can a polygon contain
another polygon?

I can see that if you had ...

e_1 = [(0,0),(3,0)]
e_2 = [(3,0),(2,3)]
e_3 = [(2,3),(0,0)]
triangle_1 = [e_1,e_2,e_3]

w_1 = [triangle_1,]

.... you might want to make a copy of triangle_1 that was offset by
some amount and add it to w_1. Is that the idea?
 
C

castironpi

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]]]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top