Author mnewman
Recipients georg.brandl, mnewman
Date 2009-03-21.18:10:43
SpamBayes Score 8.52746e-10
Marked as misclassified No
Message-id <1237659046.24.0.591034615164.issue5532@psf.upfronthosting.co.za>
In-reply-to
Content
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']
>>>
History
Date User Action Args
2009-03-21 18:10:46mnewmansetrecipients: + mnewman, georg.brandl
2009-03-21 18:10:46mnewmansetmessageid: <1237659046.24.0.591034615164.issue5532@psf.upfronthosting.co.za>
2009-03-21 18:10:44mnewmanlinkissue5532 messages
2009-03-21 18:10:43mnewmancreate