|
|
|
|
|
by duckerude
2085 days ago
|
|
I wouldn't endorse that code, but it does make sense. You can read it like this: sums = []
s = 0
for x in data:
s = s + x
sums.append(s)
`for s in [0]` assigns 0 to `s`, as an initial value. `for s in [s + x]` adds `x` to `s`. Both instances of `s` are the same variable, there's no shadowing going on. |
|