How to get a centered mean (excluding max and min value) of a list in Python? I'm learning Python &amp; practising from this site and here is the particular problem at hand:

Return the &quot;centered&quot; average of an array of ints, which we'll say is the mean average of the values, except ignoring the largest and smallest values in the array. If there are multiple copies of the smallest value, ignore just one copy, and likewise for the largest value. Use int division to produce the final average. You may assume that the array is length 3 or more.
centered_average([1, 2, 3, 4, 100]) → 3
centered_average([1, 1, 5, 5, 10, 8, 7]) → 5
centered_average([-10, -4, -2, -4, -2, 0]) → -3

My solution is as follows:
def centered_average(nums):
  items = len(nums)
  total = 0
  high = max(nums)
  low = min(nums)
  for num in nums:
    total += num
  aveg = (total -high-low) / (items-2)
  return aveg

The above code works fine. I want to ask more experienced programmers if this could be done in a better manner - or is this solution fine?
This code can be written more concisely in a couple of ways:

You can use the sum function rather than an explicit loop:

(sum(nums) - max(nums) - min(nums)) / (len(nums) - 2)


You could also use sorting and slicing to remove the extreme values, which is more concise but less efficient:

sum(sorted(nums)[1:-1]) / (len(nums) - 2)


The slice notation [1:-1] takes the elements of a list starting with the second element (index 1) and finishing with the last-but-one element (index -1, i.e. indexing from the end of the list rather than the start)

If you are using Python 3.4+ you can use the statistics module, which has a mean function:

from statistics import mean

mean(sorted(nums)[1:-1])