diff options
author | syt <syt@localhost.localdomain> | 2006-11-23 15:37:29 +0100 |
---|---|---|
committer | syt <syt@localhost.localdomain> | 2006-11-23 15:37:29 +0100 |
commit | 1bfddfdb575c57d6383efefdb13a44ccd56b3be1 (patch) | |
tree | 98c4d05d03664d0893bb672207dacc639bbc301f /__init__.py | |
parent | c642a7e6d32438bc78947b6f967a6118f3fa0650 (diff) | |
download | logilab-common-1bfddfdb575c57d6383efefdb13a44ccd56b3be1.tar.gz |
make Node iterable
Diffstat (limited to '__init__.py')
-rw-r--r-- | __init__.py | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/__init__.py b/__init__.py index 6c88683..55b1bb8 100644 --- a/__init__.py +++ b/__init__.py @@ -81,7 +81,27 @@ def union(list1, list2): return tmp.keys() -# XXX are functions below still used ? +# XXX move in a specific module + +def flatten(iterable, tr_func=None, results=None): + """flatten a list of list with any level + + if tr_func is not None, it should be a one argument function that'll be called + on each final element + """ + if results is None: + results = [] + for val in iterable: + if isinstance(val, (list, tuple)): + flatten(val, tr_func, results) + elif tr_func is None: + results.append(val) + else: + results.append(tr_func(val)) + return results + + +# XXX is function below still used ? def make_domains(lists): """ @@ -108,21 +128,3 @@ def make_domains(lists): i += 1 domains.append(new_domain) return domains - - -def flatten(iterable, tr_func=None, results=None): - """flatten a list of list with any level - - if tr_func is not None, it should be a one argument function that'll be called - on each final element - """ - if results is None: - results = [] - for val in iterable: - if isinstance(val, (list, tuple)): - flatten(val, tr_func, results) - elif tr_func is None: - results.append(val) - else: - results.append(tr_func(val)) - return results |