Updated docstring
authorThierry Florac <thierry.florac@onf.fr>
Mon, 02 Jul 2018 08:57:56 +0200
changeset 212 c110fd0251ff
parent 211 48a13f7bddbe
child 213 7d552669f29f
child 274 f139914e2eee
Updated docstring
src/pyams_utils/list.py
--- a/src/pyams_utils/list.py	Mon Jul 02 08:50:10 2018 +0200
+++ b/src/pyams_utils/list.py	Mon Jul 02 08:57:56 2018 +0200
@@ -25,7 +25,7 @@
     """Extract unique values from list, preserving order
 
     :param iterator seq: input list
-    :param callable idfun: an identity function which is used to get 'identity' value of each element
+    :param callable key: an identity function which is used to get 'identity' value of each element
         in the list
     :return: list; a new list containing only unique elements of the original list in their initial order.
         Original list is not modified.
@@ -65,9 +65,31 @@
 
 
 def unique_iter(iterable, key=None):
-    """List unique elements, preserving order. Remember all elements ever seen."""
-    # unique_everseen('AAAABBBCCDAABBB') --> A B C D
-    # unique_everseen('ABBCcAD', str.lower) --> A B C D
+    """Iterate over iterator values, yielding only unique values
+
+    :param iterator iterable: input iterator
+    :param callable key: an identity function which is used to get 'identity' value of each element
+        in the list
+    :return: an iterator of unique values
+
+    >>> from pyams_utils.list import unique_iter
+    >>> mylist = [1, 2, 3, 2, 1]
+    >>> list(unique_iter(mylist))
+    [1, 2, 3]
+
+    >>> mylist = [3, 2, 2, 1, 4, 2]
+    >>> list(unique_iter(mylist))
+    [3, 2, 1, 4]
+
+    You can also set an 'id' function applied on each element:
+
+    >>> mylist = [1, 2, 3, '2', 4]
+    >>> list(unique_iter(mylist, key=str))
+    [1, 2, 3, 4]
+    >>> mylist = ['A', 'B', 'b', '2', 4]
+    >>> list(unique_iter(mylist, key=lambda x: str(x).lower()))
+    ['A', 'B', '2', 4]
+    """
     seen = set()
     seen_add = seen.add
     if key is None: