x3m_tm

Python Advanced Exam - 24 October 2020 - 03. List Pureness

Jun 25th, 2021
1,619
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from collections import deque
  2.  
  3. def best_list_pureness(numbers, k):
  4.     data = {}
  5.     numbers = deque(numbers)
  6.    
  7.     for rotation in range(k + 1):
  8.         result = sum([index*number for index, number in enumerate(numbers)])
  9.         data.update({rotation: result})
  10.         numbers.appendleft(numbers.pop())
  11.        
  12.     max_pureness = max(data.values())
  13.     for key, val in data.items():
  14.         if max_pureness == val:
  15.             return f"Best pureness {val} after {key} rotations"
  16.  
  17.  
  18. test = ([4, 3, 2, 6], 4)
  19. result = best_list_pureness(*test)
  20. print(result)
  21.  
RAW Paste Data