A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-June/045399.html below:

[Python-Dev] Re: Candidate Itertools

[Python-Dev] Re: Candidate ItertoolsDavid Eppstein eppstein at ics.uci.edu
Tue Jun 15 17:54:39 EDT 2004
In article <000a01c452b2$a6f13b20$bfaf2c81 at oemcomputer>,
 "Raymond Hettinger" <raymond.hettinger at verizon.net> 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)

I'd probably use count_elements, but as Bob I. already said, I'd prefer 
the dict to the transposed pairs of its items.  I'm not so sure why 
pairswap would be better than the generator expression it replaces, 
though.

-- 
David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4