Advertisement
agel122

Untitled

Nov 15th, 2021
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. my_array = [[1, 2, 2], [1, 3, 2], [1, 7, 2], [
  2.     2, 4, 5], [2, 2, 3], [3, 6, 7], [3, 1, 2]]
  3. print(my_array)
  4. first_numbers = []
  5.  
  6. for item in my_array:
  7.     first_numbers.append(item[0])
  8. print(first_numbers)
  9.  
  10. set_of_first_numbers = set(first_numbers)
  11. print(set_of_first_numbers)
  12.  
  13. unique_dict = {}
  14.  
  15. for item in set_of_first_numbers:
  16.     unique_dict.setdefault(item, 0)
  17.  
  18. print(unique_dict)
  19.  
  20.  
  21. for item in my_array:
  22.     if item[0] in unique_dict.keys():
  23.         unique_dict[item[0]] += item[1] + item[2]
  24.  
  25. print(unique_dict)
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement