[Python-Dev] Candidate Itertools

Bob Ippolito bob at redivi.com
Tue Jun 15 17:44:06 EDT 2004


On Jun 15, 2004, at 4:27 AM, Raymond Hettinger wrote:

> Feedback is requested for two prospective itertools:
>
> def count_elements(iterable):
>     b = {}
>     for elem in iterable:
>         b[elem] = b.get(elem, 0) + 1
>     return ((cnt, elem) for elem, cnt in b.iteritems())
>
>
> def pairswap(iterable):
>     return ((b,a) for a,b in iterable)

pairswap would be extremely convenient, but I'm not sure about 
count_elements.  Why not just return the dict?  Or create a bucket 
type?  Why return (cnt, elem) instead of (elem, cnt) if you have 
pairswap?

-bob

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2357 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-dev/attachments/20040615/7273208e/smime.bin


More information about the Python-Dev mailing list