partial sums problem

Emile van Sebille emile at fenx.com
Wed Sep 29 01:35:16 CEST 2010


On 9/28/2010 3:57 PM kj said...
>
>
> The following attempt to get a list of partial sums fails:
>
>>>> s = 0
>>>> [((s += t) and s) for t in range(1, 10)]
>    File "<stdin>", line 1
>      [((s += t) and s) for t in range(1, 10)]
>            ^
> SyntaxError: invalid syntax
>
> What's the best way to get a list of partial sums?
>

I'm pretty sure the consensus isn't this...

 >>> R=[]
 >>> [ sum(R) for s in range(1,10) if not R.append(s) ]



Emile




More information about the Python-list mailing list