Comment

Comment by duckerude

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.
parent duckerude 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton