Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 0.27 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. >>> data = [{"class": "A", "point": 1.0}, {"class": "A", "point":2.0 }, {"class":"B", "point":3.0}]
  2. >>> def find_mean(l): return sum(map(lambda x:x['point'], l))/len(l)
  3. ...
  4. >>> dict([(k, find_mean(list(l))) for k,l in groupby(data, lambda x:x['class'])])
  5. {'A': 1.5, 'B': 3.0}