Chained assignments are banned according to the style guide at my workplace. Too many opportunities for misuse. And if you insist on a one-liner assignment to two variables just use two statements separated by the semicolon. I challenge anyone to work out what this code does:
a, b = b[a] = 1, [0, 1, 2, 3]
> I challenge anyone to work out what this code does
It's unusual, but pretty obvious. In single steps it's basically this:
which would be b[1]=b because a==1. So this creates a self referencing list. The deeper reason here is, everything is a pointer to data in memory, even if in source code we see the actual data. That's why b[1] is storing the pointer to the list, not the data of the list.If someone is doing BS like this, they deserve spanking. But banning the whole concept because people are unaware or how something is to be used properly is strange. But then again, it seems people have a bit of a problem how python really works and how it's different from other languages.