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

Posted by cocobear on Stack Overflow See other posts from Stack Overflow or by cocobear
Published on 2011-01-14T03:31:38Z Indexed on 2011/01/14 17:53 UTC
Read the original article Hit count: 212

Filed under:
|
|
|
|
>>> 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?

© Stack Overflow or respective owner

Related posts about python

Related posts about list