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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:50:06+00:00 2026-06-07T08:50:06+00:00

Alright, i am new to python, and simple tab creation in this language somewhat

  • 0

Alright, i am new to python, and simple tab creation in this language somewhat bewilders me.
I am trying to get a tabbed output like such:

:0.1
  A:0.1
  :0.9
    H:2.2
    I:3.0
    B:0.2
  :0.5
    C:0.3
    D:0.4

It is the name of a node, a colon,’:’, and its corresponding distance, the nodes with no name are designated by ‘None’ and that is because they represent only a distance to another variable. This is a tree design, so the tabs and indentations can vary.
I gather this information from a

self.name

representing the name variable, and a

self.distance

representing the distance

An unindented output of the information looks like the following:

A : 0.1
H : 2.2
I : 3.0
B : 0.2
None : 0.9
C : 0.3
D : 0.4
None : 0.5
None : 0.1

There are supposed to be 3 levels of indentations,

the root, ‘:0.1’,

its 3 children of ‘A:0.1’; ‘:0.9’; ‘:0.5’,

and ‘:0.9’ and ‘:0.5’s children, H,I,B,C and D

I apologize if this is not enough information, i am just unsure how to create a basic tabbed output like the one i’ve shown above.

Thanks!

EDIT: received my answer Thank You!

  • 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-07T08:50:08+00:00Added an answer on June 7, 2026 at 8:50 am

    Let’s say you have a tree-like data structure. I’m going to use a nested dict in this example for simplicity:

    data = {
        "A": {"value": 0.2, "children": {
                "D": {"value": 0.3, "children": {}},
                "E": {"value": 0.4, "children": {
                        "H": {"value": 0.5, "children": {}},
                        "I": {"value": 0.6, "children": {}}
                    }
                }
            }
        },
        "B": {"value": 0.7, "children": {
                "C": {"value": 0.8, "children": {}},
                "D": {"value": 0.9, "children": {}}
            }
        }
    }
    

    You could traverse and print it using the following recursive function:

    from operator import itemgetter
    
    def display(tree, depth=0):
        prepend = "\t" * depth
        for key, val in sorted(tree.items()):
            print "{0}{1}: {2}".format(prepend, key, val['value'])
            if val['children']:
                display(val['children'], depth + 1)
    

    Which displays the following output:

    >>> display(data)
    A: 0.2
        D: 0.3
        E: 0.4
            H: 0.5
            I: 0.6
    B: 0.7
        C: 0.8
        D: 0.9
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, this is probably a really silly question but I am new to Python/Django
Alright, this one's interesting. I have a solution, but I don't like it. The
Alright I'm pretty new to programming and stuff and I'm now trying to code
Alright, I'm extremely new to programming so odds are this is a really easy
Alright, so I've been trying to implement a simple binary search tree that uses
Alright, I'll preface this with the fact that I'm a GTK and Python newb,
I'm trying to create an environment using virtualenv. virtualenv test New python executable in
Alright, I will try to make this is as simple as possible, without being
Alright so I'm pretty new to this rails stuff so please bear with me...
Alright, so I'm trying out C++ for the first time, as it looks like

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.