summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/ext/iter_tools.py15
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()
r: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
*.o
*.o.depend
*.orig
*.rej
*.rej.orig
javascript.h
xxxterm
xxxterm.cat1
tags