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 8134699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:07:42+00:00 2026-06-06T10:07:42+00:00

Alright, I have this program to sparse code in Newick Format, which extracts both

  • 0

Alright,
I have this program to sparse code in Newick Format, which extracts both a name, and a distance for use in a phylogenetic tree diagram.
What my problem is, in this branch of code, as the program reads through the newickNode function, it assigns the name and distance to the ‘node’ variable, then returns it back into the ‘Node’ class to be printed, but it seems to only print the first node ‘A’, and skips the other 3.
Is there anyway to finish the for loop in newickNode to read the other 3 nodes and print them accordingly with the first?

class Node:
    def __init__(self, name, distance, parent=None):
        self.name = name
        self.distance = distance
        self.children = []  
        self.parent = parent

    def displayNode(self):
        print "Name:",self.name,",Distance:",self.distance,",Children:",self.children,",Parent:",self.parent

def newickNode(newickString, parent=None):
    String = newickString[1:-1].split(',')
    for x in String:
        splitString = x.split(':')
        nodeName = splitString[0]
        nodeDistance = float(splitString[1]) 
        node = Node(nodeName, nodeDistance, parent)
        return node

Node1 = newickNode('(A:0.1,B:0.2,C:0.3,D:0.4)')
Node1.displayNode()

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-06T10:07:44+00:00Added an answer on June 6, 2026 at 10:07 am

    You could make it a generator:

    def newickNode(newickString, parent=None):
        String = newickString[1:-1].split(',')
        for x in String:
            splitString = x.split(':')
            nodeName = splitString[0]
            nodeDistance = float(splitString[1]) 
            node = Node(nodeName, nodeDistance, parent)
            yield node
    
    for node in newickNode('(A:0.1,B:0.2,C:0.3,D:0.4)'): 
        node.displayNode()
    

    The generator will return one node at a time and pause within the function, and then resume when you want the next one.

    Or just save them up and return them

    def newickNode(newickString, parent=None):
        String = newickString[1:-1].split(',')
        nodes = []
        for x in String:
            splitString = x.split(':')
            nodeName = splitString[0]
            nodeDistance = float(splitString[1]) 
            node = Node(nodeName, nodeDistance, parent)
            nodes.append(node)
        return nodes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code, it looks alright and is really basic, but i can't
Alright, so I have this bit of code, and when I make the request,
Alright I know this is more than likely a amateur question but I have
Alright, this one's interesting. I have a solution, but I don't like it. The
Alright, this is melting my brain. It might have something to do with the
Alright, this problem is a little complicated, so bear with me. I have a
Alright, I have a UIView which displays a CGPath which is rather wide. It
Alright, so I have been wondering how to do this for a while. Basically,
Alright so I have this line in my assembly MOV EAX, DWORD PTR DS:[ESI]
I'm having a little predicament switching between views, here. Alright, so, I have this

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.