Guest User

Untitled

a guest
Apr 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. [[('a', 'b'), 1], [('b', 'c'), 2], [('a', 'b'), 5]]
  2.  
  3. s = [[('a', 'b'), 1], [('b', 'c'), 2], [('a', 'b'), 5]]
  4.  
  5. import collections
  6.  
  7. c = collections.defaultdict(list)
  8.  
  9. for t,i in s:
  10. c[t].append(i)
  11.  
  12. result = [(t,sum(v)//len(v)) for t,v in c.items()]
  13.  
  14. print(result)
  15.  
  16. [(('a', 'b'), 3), (('b', 'c'), 2)]
Add Comment
Please, Sign In to add comment