Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4061
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!d19g2000prh.googlegroups.com!not-for-mail |
|---|---|
| From | Raymond Hettinger <python@rcn.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Simple map/reduce utility function for data analysis |
| Date | Tue, 26 Apr 2011 11:12:33 -0700 (PDT) |
| Organization | http://groups.google.com |
| Lines | 26 |
| Message-ID | <71335df7-4f4a-431d-9e2c-4ba1e98c3f7d@d19g2000prh.googlegroups.com> (permalink) |
| References | <967b61ce-5641-484a-bd76-5a09bd4247e0@w9g2000prg.googlegroups.com> <7xei4pohrq.fsf@ruckus.brouhaha.com> |
| NNTP-Posting-Host | 76.94.45.111 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | posting.google.com 1303841553 19723 127.0.0.1 (26 Apr 2011 18:12:33 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Tue, 26 Apr 2011 18:12:33 +0000 (UTC) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | d19g2000prh.googlegroups.com; posting-host=76.94.45.111; posting-account=4Y7qkQkAAACIJklcr0OP4w6S6TBL_zh2 |
| User-Agent | G2/1.0 |
| X-HTTP-UserAgent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24,gzip(gfe) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4061 |
Show key headers only | View raw
On Apr 25, 7:42 pm, Paul Rubin <no.em...@nospam.invalid> wrote: > Raymond Hettinger <pyt...@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: My first draft had a defaultdict but that implementation detail would get exposed to the user unless the return value was first coerced to a regular dict. Also, I avoided modern python features so the code would run well on psyco and so that it would make sense to beginning users. > Untested: > d = defaultdict(list) > for key,value in ifilter(bool,imap(mapper, data)): > d[key].append(value) > ... Nice use of itertools. FWIW, ifilter() will accept None for the first argument -- that's a bit faster than using bool(). Raymond
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Simple map/reduce utility function for data analysis Raymond Hettinger <python@rcn.com> - 2011-04-25 16:48 -0700
Re: Simple map/reduce utility function for data analysis Paul Rubin <no.email@nospam.invalid> - 2011-04-25 19:42 -0700
Re: Simple map/reduce utility function for data analysis Raymond Hettinger <python@rcn.com> - 2011-04-26 11:12 -0700
Re: Simple map/reduce utility function for data analysis Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-26 02:52 +0000
csiph-web