473,748 Members | 9,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

data structure

Hello again.

I have a task i need to do and i can't seem to find an elegent
solution.
i need to make a tree like data structure (not necessry a binary tree).
i would like each node to access his sons in a dicionary kind of why,
for example: if ROOT node has the name 'A' and 'AA', 'AB' are his
sons, and 'ABA' is 'AB son etc' (in this name scheme the letters from
left to right shows the route from the root to the node) then
ROOT['AB'] will point to 'AB' node and ROOT['AB'][ABA'] will point to
'ABA' node.

the tree does not have to be symmarical and every node link to
different number of nodes. two nodes can have the same name if they are
in a different location in the tree. so ROOT['factory1]['manager'] and
ROOT['factory2']['manager'] can be in the same tree and point to
different objects.

all up to now i can manage.
---------------------
my problem is this: i would like to find a way to easly construct the
tree by giving some simple template, somthing similer to:
"
ROOT={'factory1 ':FACTORY,'faco ry2':FACTORY,'l inux':OS,'windo ws':OS}
FACTORY={'manag er':EMPLOEY,'wo rker':EMPLOEY,' office':BUILDIN G,'......}
OS={'ver':VERSI ON,'problems':L IST,....}
"
i started bulding the class NODE as an extention of "dict" with the
keys are the childern names and the items are the next node reference.
the proablem was that as you can see from the above example 'factory1'
and 'factory2' point to the same object. i would like to have 2
different objects of FACTORY. making FACTORY a template and not an
object.

i'll appreciate any comment
amit

Sep 3 '06 #1
1 1423
noro wrote:
Hello again.

I have a task i need to do and i can't seem to find an elegent
solution.
i need to make a tree like data structure (not necessry a binary tree).
i would like each node to access his sons in a dicionary kind of why,
for example: if ROOT node has the name 'A' and 'AA', 'AB' are his
sons, and 'ABA' is 'AB son etc' (in this name scheme the letters from
left to right shows the route from the root to the node) then
ROOT['AB'] will point to 'AB' node and ROOT['AB'][ABA'] will point to
'ABA' node.

the tree does not have to be symmarical and every node link to
different number of nodes. two nodes can have the same name if they are
in a different location in the tree. so ROOT['factory1]['manager'] and
ROOT['factory2']['manager'] can be in the same tree and point to
different objects.

all up to now i can manage.
---------------------
my problem is this: i would like to find a way to easly construct the
tree by giving some simple template, somthing similer to:
"
ROOT={'factory1 ':FACTORY,'faco ry2':FACTORY,'l inux':OS,'windo ws':OS}
FACTORY={'manag er':EMPLOEY,'wo rker':EMPLOEY,' office':BUILDIN G,'......}
OS={'ver':VERSI ON,'problems':L IST,....}
"
i started bulding the class NODE as an extention of "dict" with the
keys are the childern names and the items are the next node reference.
the proablem was that as you can see from the above example 'factory1'
and 'factory2' point to the same object. i would like to have 2
different objects of FACTORY. making FACTORY a template and not an
object.

i'll appreciate any comment
amit
You can make a shallow copy of a dictionary using the dictionary's copy
method. To make a completely new copy, use the deepcopy function in
the copy module. Please see the copy module's documentation on the
limits and differences between deep copies and shallow copies.
(http://docs.python.org/lib/module-copy.html)

--Jason

Sep 3 '06 #2

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

Similar topics

1
2105
by: dmb000006 | last post by:
Hello, I have a database style data structure, each record has several fields. I would like to create a nested data structure that would let me 'query' the data on the value of certain fields. I did this by making the following type of data...
3
2376
by: Mike Jones | last post by:
need help with data structures.Looking for ways to start, sample code, anything Program description: Design and implement a Visual C++ .NET program that inserts values into a data structure and then removes them as described below.
2
6462
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_ { char szInput; char szOutput; int iSum;
11
3188
by: theshowmecanuck | last post by:
As a matter of academic interest only, is there a way to programmatically list the 'c' data types? I am not looking for detail, just if it is possible, and what function could be used to accomplish it. For example: int main void() { while there are more data types { print next data type; }
5
4798
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e. "payload") using pointers. Examples of these are binary trees, hash tables etc. Thus, the message itself contains only a pointer to the actual data. When the message is sent to the same processor, these pointers point to the original locations, which...
3
8901
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String End Structure
11
4142
by: Macca | last post by:
Hi, I'm writing an application that will pass a large amount of data between classes/functions. In C++ it was more efficient to send a pointer to the object, e.g structure rather than passing the actual structure itself. Is this true of C# also?
3
2163
by: aurora | last post by:
This is an entry I just added to ASPN. It is a somewhat novel technique I have employed quite successfully in my code. I repost it here for more explosure and discussions. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475158 wy ------------------------------------------------------------------------
29
4263
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
30
3402
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and commits it. How does the other user get the updated view without polling for changes? Is there some sort of callback mechanism that can be set up on the dataset or connection? TIA
0
8826
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,...
1
9316
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
8239
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...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
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...
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
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.