Why does a = a['k'] = {} create an infinitely nested dictionary?
stackoverflow.com
stackoverflow.com
a=a['k']={} is also valid JavaScript, however running it throws an exception and generally works as OP probably expected the statement to work.
The reason is that in JS, the statement is parsed as
a = (a['k']={})
where (a['k']={}) is executed first and also returns the assigned value.Meanwhile in Python, apparently multi-assignment is a grammar production of its own, so the above would be parsed as sort of:
multi-assign(a, a['k']) = {}
and therefore first assign to a, then to a['k']. a['k'] = a = {}
won't still work.I think that one thing that makes the statement confusing is that the first equals sign serves a purpose completely different from the second equals sign, but both of them are represented by the same character.