diff options
author | hut <hut@lavabit.com> | 2013-02-10 03:28:06 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2013-02-10 03:35:27 +0100 |
commit | d1a1173ddc315f21a3d468f43ac55aa43d31883d (patch) | |
tree | 10d728b37294856eb21e6e962089ac38507d868c /ranger/ext/iter_tools.py | |
parent | 184e84284d2f4e48631a4b94b87ba76126470206 (diff) | |
download | ranger-d1a1173ddc315f21a3d468f43ac55aa43d31883d.tar.gz |
replaced tabs with 4 spaces in all python files
PEP 8 (Style Guide for Python Code) suggests the use of 4 spaces: http://www.python.org/dev/peps/pep-0008/#indentation If you need to use tools like "git blame", you can use the -w option to ignore this commit entirely. Patches will continue to work if you substitute tabs with 4 spaces everywhere except in the Makefile.
Diffstat (limited to 'ranger/ext/iter_tools.py')
-rw-r--r-- | ranger/ext/iter_tools.py | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/ranger/ext/iter_tools.py b/ranger/ext/iter_tools.py index 341230f4..9e8fcd74 100644 --- a/ranger/ext/iter_tools.py +++ b/ranger/ext/iter_tools.py @@ -4,44 +4,44 @@ from collections import deque def flatten(lst): - """ - Flatten an iterable. - - 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)): - for subelem in flatten(elem): - yield subelem - else: - yield elem + """ + Flatten an iterable. + + 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)): + for subelem in flatten(elem): + yield subelem + else: + yield elem def unique(iterable): - """ - Return an iterable of the same type which contains unique items. - - 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) + """ + Return an iterable of the same type which contains unique items. + + 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() + import doctest + doctest.testmod() |