Message83943
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']
>>> |
|
Date |
User |
Action |
Args |
2009-03-21 18:10:46 | mnewman | set | recipients:
+ mnewman, georg.brandl |
2009-03-21 18:10:46 | mnewman | set | messageid: <1237659046.24.0.591034615164.issue5532@psf.upfronthosting.co.za> |
2009-03-21 18:10:44 | mnewman | link | issue5532 messages |
2009-03-21 18:10:43 | mnewman | create | |
|