Adding a simple iterator to the Trie class, now the set operations
authorFredrik Unger <fred@tree.se>
Wed, 6 Apr 2011 20:51:03 +0000 (22:51 +0200)
committerFredrik Unger <fred@tree.se>
Wed, 6 Apr 2011 20:51:03 +0000 (22:51 +0200)
on the links in the tree works again.

src/tree-cutter.py

index 4c0f01946f1e748d45c23bef388fbf4110ba5d3b..0b72e6b5a0d7e36b0f5295b704e49c2b917cc92f 100755 (executable)
@@ -193,6 +193,15 @@ class Trie():
     def __init__(self):
         self._root = []
 
+    def __iter__(self):
+        return self.inorder(self._root)
+
+    def inorder(self,t):
+        for l in t:
+            yield l.value()
+            for ch in l.children():
+                self.inorder(ch)
+
     def _add(self,trie, key, content):
         # is the key a leaf
         k = key.pop(0)