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