Calculating a moving average - using python

Question

You are given a list of numbers J and a single number p. Write a function to return the minimum and maximum averages of the sequences of p numbers in the list J.

For example:

# Array of numbers
J = [4, 4, 4, 9, 10, 11, 12]

# Length of sequences, p
p = 3

Here, the sequences will be:

  • (4,4,4)
  • (4,4,9)
  • (4,9,10)
  • (9,10,11)
  • (10,11,12)

From the above we can see that the minimum average will be 4 and the maximum average will be 11, which corresponds to the first and last sequences.

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now