I have a question. I have a list of numbers like:

Bobby 9 9 8 4 8 5 6 7 3 8 6 5 5 7 6 9 6 4 6 4 3 4 7 6 6

I have already written a code to take the numbers in range (1,15) and I have already written the code to average these numbers. The question is does anyone know how I could take the lowest 5 numbers in the range and replace them with the highest five numbers in the same range, so when I compute the average instead of an average of these numbers the lowest 5 are replaced by the highest 5 and that is the new average.So in this example a 4,5,5,5,3 would be replaced by 9,9,8,8,8.

Any ideas?

1) Choose a title that will get people to read the question
2) Sort the list and replace the first 5 numbers with the last 5

I have a question. I have a list of numbers like:

Bobby 9 9 8 4 8 5 6 7 3 8 6 5 5 7 6 9 6 4 6 4 3 4 7 6 6

I have already written a code to take the numbers in range (1,15) and I have already written the code to average these numbers. The question is does anyone know how I could take the lowest 5 numbers in the range and replace them with the highest five numbers in the same range, so when I compute the average instead of an average of these numbers the lowest 5 are replaced by the highest 5 and that is the new average.So in this example a 4,5,5,5,3 would be replaced by 9,9,8,8,8.

Any ideas?

Push numbers (or heapify inplace) in heap and use heapq.nlargest heapq.nsmallest

Push numbers (or heapify inplace) in heap and use heapq.nlargest heapq.nsmallest

I have the list of numbers in my range in variable a so would I say

heapq.nlargest (a)

heapq.nsmallest (a)

when i do this is says heapq not defined

see collections module. Maybe sorting and slice assignement would do as well like woooee said.