On 21/09/2013 13:53, Dave Angel wrote:
[snip]
Taking Steven's suggested code, and changing it so it uses a COPY of the
global list;

def median():
     # Relies on the global variable called List.
     # assumes there is at least one number in that list
     numbers = List.sorted()

That should be:

     numbers = sorted(List)

     n = len(numbers)
     if n % 2 == 1:
         # Odd number of items.
         return numbers[n//2]
     else:
         a = numbers[n//2 - 1]
         b = numbers[n//2]
         return (a + b)/2.0


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to