fork download
  1. m, n, numbers = 4, 6, [10, 12, 10, 7, 4, 22]
  2.  
  3. numbers.sort()
  4. i = min(range(n-m+1), key=lambda i: numbers[i+m-1] - numbers[i])
  5. print numbers[i:i+m]
Success #stdin #stdout 0.01s 7736KB
stdin
Standard input is empty
stdout
[7, 10, 10, 12]