diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-02-06 03:01:24 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-02-06 03:01:24 (GMT) |
commit | 063ff65e2c305a8f24100475cc4f9ad2bcc342be (patch) | |
tree | d2bf4831013b53844a40cb8ca865a1be90243edd /Doc/library | |
parent | 7f9876c0daf73b1da3a7bc3ab62add0d1b10706a (diff) | |
download | cpython-063ff65e2c305a8f24100475cc4f9ad2bcc342be.zip cpython-063ff65e2c305a8f24100475cc4f9ad2bcc342be.tar.gz cpython-063ff65e2c305a8f24100475cc4f9ad2bcc342be.tar.bz2 |
Merged revisions 69141,69211-69212 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r69141 | benjamin.peterson | 2009-01-31 14:01:48 -0600 (Sat, 31 Jan 2009) | 1 line
fix indentation
........
r69211 | guilherme.polo | 2009-02-02 14:23:29 -0600 (Mon, 02 Feb 2009) | 1 line
Restore the previous geometry before leaving the test
........
r69212 | guilherme.polo | 2009-02-02 14:28:59 -0600 (Mon, 02 Feb 2009) | 1 line
Moving to importlib
........
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/itertools.rst | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 634b909..8346587 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -654,26 +654,26 @@ which incur interpreter overhead. s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) - def unique_everseen(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 - seen = set() - seen_add = seen.add - if key is None: - for element in iterable: - if element not in seen: - seen_add(element) - yield element - else: - for element in iterable: - k = key(element) - if k not in seen: - seen_add(k) - yield element - - def unique_justseen(iterable, key=None): - "List unique elements, preserving order. Remember only the element just seen." - # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B - # unique_justseen('ABBCcAD', str.lower) --> A B C A D - return map(next, map(itemgetter(1), groupby(iterable, key))) + def unique_everseen(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 + seen = set() + seen_add = seen.add + if key is None: + for element in iterable: + if element not in seen: + seen_add(element) + yield element + else: + for element in iterable: + k = key(element) + if k not in seen: + seen_add(k) + yield element + + def unique_justseen(iterable, key=None): + "List unique elements, preserving order. Remember only the element just seen." + # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B + # unique_justseen('ABBCcAD', str.lower) --> A B C A D + return map(next, imap(itemgetter(1), groupby(iterable, key))) |