474,029 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

recursively change values in list of lists

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
Aug 24 '08 #1
3 1315
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?
Aug 24 '08 #2
On Aug 24, 9:17*am, "Carson Farmer" <carson.far...@ gmail.comwrote:
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]]]
Aug 24 '08 #3
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
Aug 24 '08 #4

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

Similar topics

4
5150
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 Regards, Nicolas
10
6036
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 levels. I changed the width of the first level to 8em and get an unwanted space between that and the 2nd level. I'd like their to be no gap between the levels when I change the widths. What's to change to do this? Also, I do not understand the...
24
4027
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 = s2 = s3 = for value in ???(s1, s2, s3):
11
6114
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 dicts with larger no. of features. Now i want to check each pair to see if they are connected...element of this pair will be one from the first list and one from the second....e.g for 'ab' i want to check if 1 and 3 are connected,then 1 and...
14
3526
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 list? I know that sets were introduced a lot later and lists/dictionaries were used instead but I think "the only correct way" now is for the dictionary keys and values to be sets. Presently {1:0,2:0,3:0}.keys() will produce but it could also...
2
12457
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 into converting into code.
8
2395
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 dependencies of those dependencies and so on. I managed to do it, but I'm not really happy with the method, and I'm wondering if anyone can suggest something better. My technique involves manipulating a string containing the names, calling a...
19
2009
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 consolidate all my JSON lists into one and modify my scripts so that they were more generic and reusable. So far so good. The problem is that my JSON lists used variables for many pieces of code that performed multiple iterations to create several...
0
717
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 point in line : point += x point += y
0
10512
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11580
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11932
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11105
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10270
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6614
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4911
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.