Skip to content

Instantly share code, notes, and snippets.

@a-recknagel
Created August 20, 2018 10:49
Show Gist options
  • Save a-recknagel/1380a2576de27cb94a6cd88e799e748f to your computer and use it in GitHub Desktop.
Save a-recknagel/1380a2576de27cb94a6cd88e799e748f to your computer and use it in GitHub Desktop.
assex leaking listcomp
>>> total = 0
>>> [total := total + v for v in [1, 2, 3]]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <listcomp>
UnboundLocalError: local variable 'total' referenced before assignment
>>> total # ?!?!
0 # D=
>>> [(total := total + v) for v in values] # parantheses don't solve the problem
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <listcomp>
UnboundLocalError: local variable 'total' referenced before assignment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment