diff options
-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): |