Useful module to be written by a newbie

Peter Otten __peter__ at web.de
Thu Apr 30 00:00:54 CEST 2015


Cecil Westerhof wrote:

> Op Wednesday 29 Apr 2015 21:03 CEST schreef Peter Otten:

>> I was judging from the look of your MovingAverage.
>>
>> I don't like the interface, it really should take an iterable so
>> that you can write
>>
>>>>> list(moving_average([1,2,3], 2))
>> [1.5, 2.5]
> 
> I should probably document it better. The idea is that you do not have
> the data yet. At certain intervals data is acquired and at that moment
> you want the moving average with the new data. But it would not hurt
> to have the possibility to feed it a list of values, beside single
> value. Something to better the function. Thanks.

With that explanation and especially Ian's motivational excursion it makes 
more sense. My conclusion "ah newbie, doesn't know/shuns iterator protocol" 
may be wrong. However, it may be better to follow Ian's example and decouple 
adding a new value and reading the current average.





More information about the Python-list mailing list