Simple map/reduce utility function for data analysis

Paul Rubin no.email at nospam.invalid
Tue Apr 26 04:42:17 CEST 2011


Raymond Hettinger <python at rcn.com> writes:
> Here's a handy utility function for you guys to play with:
>     http://code.activestate.com/recipes/577676/

Cute, but why not use collections.defaultdict for the return dict?
Untested:

   d = defaultdict(list)
   for key,value in ifilter(bool,imap(mapper, data)):
      d[key].append(value)
   ...



More information about the Python-list mailing list