Given the sorted list
item_list = [41, 53, 54, 57, 315, 324, 340]
How would I find the three values that have the lowest standard deviation from their own average? The correct answer for the example is these three values
answer = [53, 54, 57]
They have an average of 54,66 and a standard deviation of 1,55. Any other combination would yield a higher standard deviation.
All I can think of at this moment is simply iterate through available options and calculate each. Given this 7 item list that would be 7 * 6 * 5 = 210 options I believe. But since in my actual application the list is much longer, this would perhaps lead to issues.
Also, as the list size increases, I need to be able do the same for 4, 5, 6 etc. number of elements.
Edit:
It's not a duplicate I believe. There is no code example as I didn't think my nested implementation of this bit of pseudocode;
for item in item_list:
# calculate average with all variations of 2 other elements
for each average:
# calculate standard deviation
Would be very useful, nor readable. I tried to present the minimal viable case, starting from scratch, and really had no idea where to go from there.