partial sums problem
Gary Herron
gherron at digipen.edu
Tue Sep 28 19:29:50 EDT 2010
On 09/28/2010 03:57 PM, 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?
>
> TIA!
>
> kj
>
Program in C (if that's what you want), or learn Python (if you'd
prefer), but don't try to mix the two.
Python does have "s+=t" as a statement, and it does have list
comprehensions [... for ...] as expressions, but you cannot put a
statement inside an expression.
--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418
More information about the Python-list
mailing list