time series calculation in list comprehension?

Terry Reedy tjreedy at udel.edu
Fri Mar 10 19:12:06 CET 2006


"falcon" <shahbazc at gmail.com> wrote in message 
news:1142012049.892323.103060 at v46g2000cwv.googlegroups.com...
> Is there a way I can do time series calculation, such as a moving
> average in list comprehension syntax?  I'm new to python but it looks
> like list comprehension's 'head' can only work at a value at a time.  I
> also tried using the reduce function and passed in my list and another
> function which calculates a moving average outside the list comp. ...
> but I'm not clear how to do it.  Any ideas?  Thanks.

Write explicit for loops, possibly with nested if conditionals, that do 
exactly what you want.  The functional expressions are abbreviations for 
certain patterns of induction.  Except as an educational exercise, I do not 
think it worthwhile to go through contortions to force fit a problem to a 
pattern it does not really fit.

Terry Jan Reedy






More information about the Python-list mailing list