Is there such a thing as an ordered dict?
VanL
news at lindbergs.org
Fri May 10 00:41:51 EDT 2002
I am trying to implement an outline as a tree of nodes. This would seem
to be most easily accomplished using a dict, where the name of the node
was the key, and the value of the node the hash (including any subnodes).
Unfortunately, the outline needs to also be order-aware -- that is, I
can't have a user enter an outline like this
I Head 1
A. Subhead 1 (content)
B. Subhead 2 (content)
II. Head 2 (content)
III. Head 3
and have it be printed as
II. Head 2 (content)
III Head 3
I Head 1
B. Subhead 2 (content)
A. Subhead 1 (content)
Is there some sort of halfway-dict halfway-list that could be accessed
by key *and* by position? So that the following would work:
[ Assume half-and-half structure as described above, with the outline
above entered in an instance called OUTLINE]
>>> 'Head 2' in OUTLINE
1
>>> OUTLINE['Head 2']
'(content)'
>>> for x in OUTLINE: print x, OUTLINE[x]
'Head 1' ['Subhead 1', 'Subhead 2']
'Head 2'
'Head 3' '(content)'
>>> for x in range(len(OUTLINE)): print x, OUTLINE[x]
0 'Head 1'
1 'Head 2'
2 'Head 3'
TIA
More information about the Python-list
mailing list