[Python-Dev] Candidate Itertools

Michael Hudson mwh at python.net
Thu Jun 17 05:15:39 EDT 2004


"Raymond Hettinger" <raymond.hettinger at verizon.net> writes:

> 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())

Mmm, possibly.  I've written this farily often.  As other said, I
think I'd prefer the dict.

> def pairswap(iterable):
>     return ((b,a) for a,b in iterable)

What's the point?  It's so short as a genxp...

Cheers,
mwh

-- 
  "Also, does the simple algorithm you used in Cyclops have a name?"
  "Not officially, but it answers to "hey, dumb-ass!"
                       -- Neil Schemenauer and Tim Peters, 23 Feb 2001



More information about the Python-Dev mailing list