R. David Murray added the comment: The behavior is consistent:
>>> a = [1, 2] >>> b = [3, 4] >>> [(a, b) for a in a for b in b] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 1, in <listcomp> UnboundLocalError: local variable 'b' referenced before assignment I'm not sure why it is only the nested loop that raises the error (https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries seems to imply it should raise for both) By the way, the actual result of your comprehesion would be {"a": 2, "b" 2}. ---------- nosy: +r.david.murray _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue31126> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com