SHARE
TWEET

get_same_mean

DeaD_EyE Jul 8th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. """
  4. I am not sure if the implementation is correct, but you get back as result:
  5. [[1,2,4,5]]
  6. """
  7. from statistics import mean
  8.  
  9.  
  10. def get_same_mean(data):
  11.     results = []
  12.     for i in data:
  13.         new_data = data.copy()
  14.         new_data.remove(i)
  15.         if mean(data) == mean(new_data):
  16.             if new_data in results:
  17.                 continue
  18.             results.append(new_data)
  19.     return results
  20.  
  21.  
  22. data = list(range(1,6))
  23. print('Data:')
  24. print(data)
  25. results = get_same_mean(data)
  26. print('Results:')
  27. print(results)
  28.  
  29.  
  30. # output
  31. # Data:
  32. # [1, 2, 3, 4, 5]
  33. # Results:
  34. # [[1, 2, 4, 5]]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top