bzaghalarov

Untitled

Jul 26th, 2022
1,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. # Implement @try_this decorator here )
  2. import queue
  3. import threading
  4. import time
  5.  
  6. DATA = {
  7.     'name': 'MainCategory',
  8.     'values': [
  9.         {
  10.             'name': 'Category1',
  11.             'values': [2, 5, 6]
  12.         }, {
  13.             'name': 'Category2',
  14.             'values': [4, 7, 1]
  15.         }, {
  16.             'name': 'Category3',
  17.             'values': [3, 2, 8]
  18.         }
  19.     ]
  20. }
  21.  
  22.  
  23. def calculate(data: dict) -> list:
  24.     """
  25.    Note: Each column in data represents a monthly sales for the category.
  26.    This function calculates total sales for each month.
  27.    """
  28.  
  29.     return [sum(col) for col in zip(*[row for row in [val['values'] for val in data['values']]])]
  30.  
  31.  
  32. if __name__ == '__main__':
  33.     assert calculate(DATA) == [9, 14, 15]
Advertisement
Add Comment
Please, Sign In to add comment