Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:35:22+00:00 2026-06-17T12:35:22+00:00

This is a rather specific question but since I could not figure out what

  • 0

This is a rather specific question but since I could not figure out what happens here, let me present you the problem:

Growing a decision tree, I have a splitting function that splits a node, that is it attaches two children to a node. For some reason, the code below assigns a node itself as a child such that id(currentNode.children[0])==id(currentNode):

def split(currentNode):
    if impure(currentNode.data):
        currentNode.attribute = getBestAttr(currentNode.attributes,currentNode.data);
        childrenAttributes = deepcopy(currentNode.attributes);
        childrenAttributes.remove(currentNode.attribute);
        childrenData = splitData(currentNode.data,currentNode.attribute);
        for i in range(2):            
            currentNode.children[i] = node(childrenData[i],childrenAttributes);
            split(currentNode.children[i]);

Where the crucial part is probably:

for i in range(2):            
    currentNode.children[i] = node(childrenData[i],childrenAttributes);
    split(currentNode.children[i]);

From my understanding, the constructor call should return a reference to the newly created node object which can in no way be the same as the reference to the parent node, because it is a NEW object.

The node object is:

class node:    
    data = None;
    attributes = None;    
    attribute = None;    
    children = [None,None];

    def __init__(self,data,attributes):
        self.data = data;
        self.attributes = attributes;

As I am new to oop in Python and not very experienced in oop in general, I expect that I have some misunderstanding in this respect, but I can’t figure out how to specify the question. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:35:22+00:00Added an answer on June 17, 2026 at 12:35 pm

    Hey Tobias it’s Anjana.

    Could the problem have to do with the fact that in the node class declaration (or definition or whatever), you’re defining data, attributes, attribute, and children as class-level attributes? That means when you create a new Node object, the Node.children value will not change, and for any object that instantiates the Node class, e.g. thisnode = Node(), thisnode.children will be the same as for all other node objects (thisnode.children = Node.children)

    If you want it to be different for every node object, then you have to set it up it in the init method (like self.children).

    Not sure if that has anything to do with it… let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a rather vague question but here we go - I would like
This question is not an implementation specific question of the grails plugin, but more
This is a design question rather than a Java-specific question, but I'm designing it
I don't know if this question would fit better on superuser.com , but since
This is a question about Application design rather than how-to-do specific actions. I am
this is more of an algorithmic question rather than a specific language question, so
So this is as much a theoretical question as a language-specific one, but consider
There may actually not be an answer to this question, but I wanted to
I've been having this rather frustrating problem, and having failed so many times, I'm
I know this is rather laughable, but I can't seem to get simple C++

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.