Python: Expanding Complicated Tree Datastructure
I am exploring a data structure which get expands to sub-elements and resolves to a final element. But I only want to store top two levels. Example: Lets say I start with New York
Solution 1:
Are you trying to lookup "Queens" and learn that it is in the USA? Have you tried encoding your tree in XML, and using lxml.etree
to find an element and then use getpath
to return the path in XPath format?
This would meaning adding a fourth top level to your tree, namely World, and then you would search for Queens and learn that the path to Queens is World/USA/NewYork/Queens
. The answer to your question would always be the second item in the XPath
.
Of course you could always just build a tree from the XML and use a tree search algorithm.
Post a Comment for "Python: Expanding Complicated Tree Datastructure"