On 04/13/12 22:54, Chris Angelico wrote:
Yes, that would be the right method to use. I'd not bother with the
function and map() though, and simply iterate:

d = {}
for val in l:
  d.setdefault(f(val), []).append(val)

Or make d a defaultdict:

  from collections import defaultdict
  d = defaultdict(list)
  for val in l:
    d[f(val)].append(val)

-tkc


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to