This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: imap usage in itertools unique_justseen recipe
Type: Stage:
Components: Documentation Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: benjamin.peterson, georg.brandl, mnewman, rhettinger
Priority: normal Keywords:

Created on 2009-03-21 18:10 by mnewman, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg83943 - (view) Author: Michael Newman (mnewman) Date: 2009-03-21 18:10
The recipe for "unique_justseen" listed on:
http://docs.python.org/3.0/library/itertools.html
uses "imap", which is not available in Python 3.0.

I fixed it by changing "imap" to just "map", and I also changing
"itemgetter" to "operator.itemgetter" to make the namespace usage
clearer in the recipe:

Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from itertools import *
>>> import operator
>>> 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(operator.itemgetter(1), groupby(iterable,
key)))
...
>>> unique_justseen('AAAABBBCCDAABBB')
<map object at 0x00BB2690>
>>> list(unique_justseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D', 'A', 'B']
>>> unique_justseen('ABBCcAD', str.lower)
<map object at 0x00BB2650>
>>> list(unique_justseen('ABBCcAD', str.lower))
['A', 'B', 'C', 'A', 'D']
>>>
msg83949 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-03-21 19:15
Benjamin, please revert r69354 which was an incorrect merge.
msg83976 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-03-22 17:22
Done in r70520.
History
Date User Action Args
2022-04-11 14:56:46adminsetgithub: 49782
2009-03-22 17:22:50benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg83976
2009-03-21 19:15:19rhettingersetassignee: rhettinger -> benjamin.peterson

messages: + msg83949
nosy: + benjamin.peterson
2009-03-21 18:44:51benjamin.petersonsetassignee: georg.brandl -> rhettinger

nosy: + rhettinger
2009-03-21 18:10:44mnewmancreate