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