[New-bugs-announce] [issue5532] imap usage in itertools unique_justseen recipe

Michael Newman report at bugs.python.org
Sat Mar 21 19:10:46 CET 2009

New submission from Michael Newman <michael.b.newman at gmail.com>:

The recipe for "unique_justseen" listed on:
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
...     # 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,
>>> 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']

assignee: georg.brandl
components: Documentation
messages: 83943
nosy: georg.brandl, mnewman
severity: normal
status: open
title: imap usage in itertools unique_justseen recipe
versions: Python 3.0

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list