From: Fredrik Unger Date: Wed, 6 Apr 2011 20:51:03 +0000 (+0200) Subject: Adding a simple iterator to the Trie class, now the set operations X-Git-Tag: v1.0~19 X-Git-Url: https://source.tree.se/git?p=treecutter.git;a=commitdiff_plain;h=c5df534b7acd4681ff675ab74c0d469c125d79e5 Adding a simple iterator to the Trie class, now the set operations on the links in the tree works again. --- diff --git a/src/tree-cutter.py b/src/tree-cutter.py index 4c0f019..0b72e6b 100755 --- a/src/tree-cutter.py +++ b/src/tree-cutter.py @@ -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)