[Python-Dev] Candidate Itertools
Aahz
aahz at pythoncraft.com
Thu Jun 17 20:23:01 EDT 2004
On Tue, Jun 15, 2004, Raymond Hettinger 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())
+1 provided it returns either (elem, cnt) or the dict itself.
> def pairswap(iterable):
> return ((b,a) for a,b in iterable)
-1 -- too trivial.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"Typing is cheap. Thinking is expensive." --Roy Smith, c.l.py
More information about the Python-Dev
mailing list