[Python-Dev] Re: Candidate Itertools
eppstein at ics.uci.edu
Thu Jun 24 15:11:50 EDT 2004
In article <20040622035255.GB1891 at panix.com>,
Aahz <aahz at pythoncraft.com> wrote:
> > Hmm, there seems to be 100% support for returning a dictionary and zero
> > support for my iterable (cnt, elem) ... to feed min(), max(), sorted(),
> > nlargest(), and nsmallest().
> The problem is that it's useful for those operations -- and nothing
> else. It's narrow functionality, and anyone looking just at itertools
> will find this confusing; it's just not the natural definition for
> something named ``count_elements``, and I suspect it is not possible to
> create a good name for your purpose. Anyone who understands Python will
> expect ``count_elements`` to return (elem,cnt) or a dict.
I finally found the recent code where I'd used something like this
(for the curious: http://www.ics.uci.edu/~eppstein/numth/egypt/egypt.py)
I wrote it as a function that returns a dict (itemCounts in the above
source) but what I actually did with the results in one place was to
sort the (elem,cnt) pairs by elem (not by cnt) and then iterate through
them in sorted order. In another place I used the dictionary directly
but it amounted to the same thing.
So, either of Aahz's suggestions would have worked for me but the
original (cnt,elem) suggestion wouldn't have been right.
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
More information about the Python-Dev