partial sums problem
MRAB
python at mrabarnett.plus.com
Tue Sep 28 19:36:03 EDT 2010
On 28/09/2010 23:57, kj wrote:
>
>
> 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?
>
Probably:
s = 0
p = []
for t in range(1, 10):
s += t
p.append(s)
More information about the Python-list
mailing list