On Sat, Jun 19, 2004, Raymond Hettinger wrote: > [Aahz] >>Raymond: >>> >>> 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()) >> >> +1 provided it returns either (elem, cnt) or the dict itself. > > 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. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Typing is cheap. Thinking is expensive." --Roy Smith, c.l.py
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