diff options
author | hut <hut@lavabit.com> | 2011-10-08 00:18:01 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-10-08 00:18:01 +0200 |
commit | 5603e0fa3efc1c21c2b05570f1c345b64ad26876 (patch) | |
tree | a6c304148a1e157a100805fcb1b57f20e0323bad | |
parent | 7ed4e620b2dbdb3f3af5c9ce2a3e2a3cd748b95f (diff) | |
download | ranger-5603e0fa3efc1c21c2b05570f1c345b64ad26876.tar.gz |
ext.iter_tools: Added doctest
-rw-r--r-- | ranger/ext/iter_tools.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ranger/ext/iter_tools.py b/ranger/ext/iter_tools.py index 462c0c22..f1cb2d74 100644 --- a/ranger/ext/iter_tools.py +++ b/ranger/ext/iter_tools.py @@ -21,6 +21,12 @@ def flatten(lst): All contained tuples, lists, deques and sets are replaced by their elements and flattened as well. + + >>> l = [1, 2, [3, [4], [5, 6]], 7] + >>> list(flatten(l)) + [1, 2, 3, 4, 5, 6, 7] + >>> list(flatten(())) + [] """ for elem in lst: if isinstance(elem, (tuple, list, set, deque)): @@ -36,9 +42,18 @@ def unique(iterable): This function assumes that: type(iterable)(list(iterable)) == iterable which is true for tuples, lists and deques (but not for strings) + + >>> unique([1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 1, 1, 2]) + [1, 2, 3, 4] + >>> unique(('w', 't', 't', 'f', 't', 'w')) + ('w', 't', 'f') """ already_seen = [] for item in iterable: if item not in already_seen: already_seen.append(item) return type(iterable)(already_seen) + +if __name__ == '__main__': + import doctest + doctest.testmod() |