473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Re: recursively change values in list of lists

On Sun, Aug 24, 2008 at 10:17 AM, Carson Farmer <ca***********@gmail.comwrote:
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,
You gave the solution yourself.

I don't know if your inner polygons can contain lines and polygons, or
only lines, so:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2008 Medardo Rodriguez (Merchise Group)
#
# This is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License (GPL) as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# :)

def MoveDelta(target, dx, dy):
for item in target:
if isinstance(item[0], list): # is item a polygon?
MoveDelta(item, dx, dy) # Recursive version
else:
assert len(item) == 2 # make sure that it is a point
item[0] += dx
item[1] += dy

if __name__ == '__main__':
sample = [[[1, 2], [3, 4]], [[[7, 8], [10, 20]], [5, 6]]]
print 'Original:', sample
MoveDelta(sample, 10, 100)
print 'Result:', sample

# Regards
Aug 24 '08 #1
0 809

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nicolas Fleury | last post by:
Hi everyone, Is there a way to compare recursively two objects (compare their members recursively)? I'm only interested in equality or non-equality (no need for lower-than...). Thx and...
10
by: Richard | last post by:
The style sheet shown below is from the suckerfish vertical menu. http://www.htmldog.com/articles/suckerfish/dropdowns/example/vertical.html I've added in a few minor changes to color code the...
24
by: Lasse Vågsæther Karlsen | last post by:
I need to merge several sources of values into one stream of values. All of the sources are sorted already and I need to retrieve the values from them all in sorted order. In other words: s1 = ...
11
by: Girish Sahani | last post by:
I wrote the following code to concatenate every 2 keys of a dictionary and their corresponding values. e.g if i have tiDict1 = tiDict1 = {'a':,'b':} i should get tiDict2={'ab':} and similarly for...
14
by: vatamane | last post by:
This has been bothering me for a while. Just want to find out if it just me or perhaps others have thought of this too: Why shouldn't the keyset of a dictionary be represented as a set instead of a...
2
by: Eric Layman | last post by:
Hi, I have a radio button and a combo box. Upon changing a value for radio button, the combo box values will be dynamically updated. I have an idea on how to go abt doing it but Im stuck...
8
by: Scott Sauyet | last post by:
I found myself needing to find my way recursively through a document in XSLT, finding the dependencies one element had on others, and including only those in an initial set, their dependencies, the...
19
RMWChaos
by: RMWChaos | last post by:
Previously, I had used independent JSON lists in my code, where the lists were part of separate scripts. Because this method did not support reuse of a script without modification, I decided to...
3
by: Carson Farmer | last post by:
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...
0
by: Maric Michaud | last post by:
Le Sunday 24 August 2008 16:17:46 Carson Farmer, vous avez écrit : As you know the structure by advance, this is not a recusive problem : for polygon in multi : for line in polygon : for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.