Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- d = {Apple: [[Category1, 14], [Category2, 12], [Category2, 8]], Orange : [[Category2, 12], [Category2, 12], [Category3, 2]]}
- d = {Apple: [[Category1, 14], [Category2, 20]], Orange: [[Category2, 24], [Category3, 2]]}
- output = defaultdict(set)
- for key, value in d.items():
- for item in value:
- total += int(value[1])
- output[key].add(value[0],total)
- total = 0
- def tally_up(dct):
- totals = dict() # Maps keys to dicts of totals
- for key, tuples in dct.items():
- subtotals = collections.defaultdict(lambda: 0) # Maps keys to counts
- for subkey, count in tuples:
- subtotals[subkey] += count
- totals[key] = dict(subtotals)
- return totals
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement