recursively change values in list of lists
castironpi at gmail.com
Sun Aug 24 16:46:49 CEST 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
> 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,
I think you would be looking at:
[ [ [ 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]]]
[[[0, 2], [2, 4]], [[6, 8]]]
More information about the Python-list