sub = [767220, 769287, 770167, 770276, 770791, 770835, 771926, 1196500, 1199789,1201485, 1206331, 1206467, 1210929, 1213184, 1213204, 1213221, 1361867, 1361921, 1361949, 1364886, 1367224, 1368005, 1368456, 1368982, 1369000, 1370365, 1370434, 1370551, 1371492, 1471407, 1709408, 1710264, 1710308, 1710322, 1710350, 1710365, 1710375]
def runningMean(seq, n=0, total=0): #function called recursively
if not seq:
return []
total = total + int(seq[-1])
if int(seq[-1]) < total/float(n+1) * 0.9: # Check your condition to see if it's time to stop averaging.
return []
return runningMean(seq[:-1], n=n+1, total=total) + [total/float(n+1)]
avg = runningMean(sub, n = 0, total = 0)
print avg #it prints the avg value which satisfies the above condition
得られる結果は次のとおりです。
[1710198.857142857, 1710330.6666666667, 1710344.0, 1710353.0, 1710363.3333333333, 1710370.0, 1710375.0]
しかし今、私は条件を満たす平均とサブリストの両方を印刷する必要があります(リストサブのアイテムはavgのアイテムよりも大きいので、avgを印刷するので、seqのアイテムも印刷する必要があります)
すなわち
[1710198.857142857, 1710330.6666666667, 1710344.0, 1710353.0, 1710363.3333333333, 1710370.0, 1710375.0]
[1709408, 1710264, 1710308, 1710322, 1710350, 1710365, 1710375]
Pythonでそのような結果をもたらすコードを変更するにはどうすればよいですか?