Can someone explain me why, when I call this function multiple times, L is never set to empty by default? But instead the result of any following call is L appended to all results of preceding calls?
The function separates the data into blocks of 7 days, starting with the last date ([::-1]), calculates the mean of each 7 days and appends the result as a value to a list. Ignores incomplete blocks
The default value for data is a list of dates in ordinal format.
def separate(data = [i for i in w][::-1],L = []):
print("separate has been called, data is %s and L is %s" % (data, L))
if len(data)<7:
return L
total = 0
dates = 0
for value in data[:7]:
if w[value] != "None":
total += float(w[value])
dates += 1
L.append(total / dates)
return separate(data[7:], L)