recursively change values in list of lists

mblume mblume at socha.net
Sun Aug 24 11:05:25 EDT 2008


Am Sun, 24 Aug 2008 15:17:46 +0100 schrieb 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,
> 
I always do something along the lines of:

for (i,obj) in enumerate(list_of_objects):
	obj = do_something_to_obj(obj)
	list_of_objects[i] = obj


HTH. YMMV.
Martin



More information about the Python-list mailing list