Python one-liner?
Evan Driscoll
edriscoll at wisc.edu
Fri Apr 13 23:42:16 EDT 2012
On 4/13/2012 22:33, Evan Driscoll wrote:
> d = {}
> def appender(e):
> d.get(f(e), []).append(e)
> map(appender, l)
Just in case it isn't clear, the above has at least two problems and
won't even come close to working. :-)
Though I might as well ask another question... if I have a dict with
values which are lists, what's a good way to say "append x to the list
at key k, creating a list if it's not there"? dict.setdefault seems
potentially promising but the docs are crappy and don't say how it works.
Evan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 552 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20120413/e6348362/attachment-0001.sig>
More information about the Python-list
mailing list