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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:34:33+00:00 2026-05-19T12:34:33+00:00

>>> s [{‘000000’: [[‘apple’, ‘pear’]]}, {‘100000’: [‘good’, ‘bad’]}, {‘200000’: [‘yeah’, ‘ogg’]}, {‘300000’: [[‘foo’, ‘foo’]]},

  • 0
>>> s
[{'000000': [['apple', 'pear']]}, {'100000': ['good', 'bad']}, {'200000': ['yeah', 'ogg']}, {'300000': [['foo', 'foo']]}, {'310000': [['#'], ['#']]}, {'320000': ['$', ['1']]}, {'321000': [['abc', 'abc']]}, {'322000': [['#'], ['#']]}, {'400000': [['yeah', 'baby']]}]

>>> for i in s:
...     print i
...
{'000000': [['apple', 'pear']]}
{'100000': ['good', 'bad']}
{'200000': ['yeah', 'ogg']}
{'300000': [['foo', 'foo']]}
{'310000': [['#'], ['#']]}
{'320000': ['$', ['1']]}
{'321000': [['abc', 'abc']]}
{'322000': [['#'], ['#']]}
{'400000': [['yeah', 'baby']]}

i want to make a tree based on the key of each element in list.

result in logic will be:

{'000000': [['apple', 'pear']]}
    {'100000': ['good', 'bad']}
    {'200000': ['yeah', 'ogg']}
    {'300000': [['foo', 'foo']]}
        {'310000': [['#'], ['#']]}
        {'320000': ['$', ['1']]}
           {'321000': [['abc', 'abc']]}
           {'322000': [['#'], ['#']]}
    {'400000': [['yeah', 'baby']]}

perhaps a nested list can implement this or I need a tree type?

  • 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-05-19T12:34:33+00:00Added an answer on May 19, 2026 at 12:34 pm

    Here’s one approach. I’m making the assumption that you can rely on your keys to represent the tree structure properly (no ‘310000’ without ‘300000’ — that would cause problems, unless you handle missing nodes when you add them to your TreeCtrl.)

    I would start by reorganizing the data, so you can retrieve the associated data for each node by key, and also store some additional information in each node.

    # original list of dicts
    tree = [{'000000': [['apple', 'pear']]},
            {'100000': ['good', 'bad']},
            {'200000': ['yeah', 'ogg']},
            {'300000': [['foo', 'foo']]},
            {'310000': [['#'], ['#']]},
            {'320000': ['$', ['1']]},
            {'321000': [['abc', 'abc']]},
            {'322000': [['#'], ['#']]},
            {'400000': [['yeah', 'baby']]}]
    
    
    # reorganize your data into a dict:
    # {'000000': {'data':[['apple', 'pear']]},
    #  '100000': {'data':['good', 'bad']}, ...
    tree = dict([(item.keys()[0], {'data':item[item.keys()[0]]})
                      for item in tree])
    

    Then go through and figure out the parent ID for each node by replacing the last non-zero digit of the key with zero, and then padding it back to the original number of digits. Update each dict with the parent ID:

    for key in tree_dict.keys():
    
        parent_id = key.strip('0')[:-1].ljust(len(key), '0')
    
        # If it's all zeros, set it to None so we know the parent is root
        if int(parent_id) == 0:
            parent_id = None
    
        tree_dict[key].update({'parent':parent_id})
    

    This sets you up nicely to use the wx.TreeCtrl, since each node now has a reference to its parent:

    {'000000':{'data': [['apple', 'pear']], 'parent': None},
     '100000':{'data': ['good', 'bad'], 'parent': None},
     '200000':{'data': ['yeah', 'ogg'], 'parent': None},
     '300000':{'data': [['foo', 'foo']], 'parent': None},
     '310000':{'data': [['#'], ['#']], 'parent': '300000'},
     '320000':{'data': ['$', ['1']], 'parent': '300000'},
     '321000':{'data': [['abc', 'abc']], 'parent': '320000'},
     '322000':{'data': [['#'], ['#']], 'parent': '320000'},
     '400000':{'data': [['yeah', 'baby']], 'parent': None}}
    

    Add the root node to your wx.TreeCtrl, and then step through the sorted dict keys, adding the data from each item to the TreeCtrl, however you want it displayed. And for each item you add, update its dict again with the TreeItemId returned by AppendItem() or InsertItem(). If the ‘parent’ value in the dict is None, you know the parent should be the root node. If it’s not, use the parent value to retrieve the TreeItemId of the parent node, which should have been updated when you added it to the TreeCtrl.

    I hope that makes sense.

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I am currently running into a problem where an element is coming back from
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a JSP page retrieving data and when single or double quotes are
The problem with unsigned char. I am reading a PPM image file which has
I'm creating a web service to transfer json to an iPhone app. I'm using

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.