Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [[('a', 'b'), 1], [('b', 'c'), 2], [('a', 'b'), 5]]
- s = [[('a', 'b'), 1], [('b', 'c'), 2], [('a', 'b'), 5]]
- import collections
- c = collections.defaultdict(list)
- for t,i in s:
- c[t].append(i)
- result = [(t,sum(v)//len(v)) for t,v in c.items()]
- print(result)
- [(('a', 'b'), 3), (('b', 'c'), 2)]
Add Comment
Please, Sign In to add comment