diff options
author | hut <hut@lavabit.com> | 2010-01-23 00:43:43 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-01-23 00:43:43 +0100 |
commit | b6d4e3e558d84ee7b211ed9332fe9b7002cb8ec2 (patch) | |
tree | 474b750a4deca3918b1852e1153a57653447c67b | |
parent | 77d3d6f556b275dc2bed79b67bee47c13267a082 (diff) | |
download | ranger-b6d4e3e558d84ee7b211ed9332fe9b7002cb8ec2.tar.gz |
added unique function, moved flatten to ext/iter_tools
-rw-r--r-- | ranger/ext/iter_tools.py (renamed from ranger/ext/flatten.py) | 14 | ||||
-rw-r--r-- | ranger/gui/curses_shortcuts.py | 2 |
2 files changed, 15 insertions, 1 deletions
diff --git a/ranger/ext/flatten.py b/ranger/ext/iter_tools.py index 55d3e82f..913b9c7d 100644 --- a/ranger/ext/flatten.py +++ b/ranger/ext/iter_tools.py @@ -27,3 +27,17 @@ def flatten(lst): 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) + """ + already_seen = [] + for item in iterable: + if item not in already_seen: + already_seen.append(item) + return type(iterable)(already_seen) diff --git a/ranger/gui/curses_shortcuts.py b/ranger/gui/curses_shortcuts.py index 1ccaddc3..2bf70da9 100644 --- a/ranger/gui/curses_shortcuts.py +++ b/ranger/gui/curses_shortcuts.py @@ -14,7 +14,7 @@ import _curses -from ranger.ext.flatten import flatten +from ranger.ext.iter_tools import flatten from ranger.shared import SettingsAware class CursesShortcuts(SettingsAware): |