Re:Why does a = a[0] = [0] create a self-referential list in...
by heavyset_go on Thursday November 18, 2021 @08:20PM
(#29272718)
Some languages wear the things that make you go WTF on their sleeves. In contrast, Python's surprises pop up slowly over time, and in places where you'd least expect them.
Re:Why does a = a[0] = [0] create a self-referential list in...
by SOLAR_FIELDS on Friday November 19, 2021 @12:22AM
(#29274097)
I wonder if it’s because of their subtlety. I assume you are referencing JavaScript, where the warts are impossible to ignore because you can’t write an everyday program as a beginner without running into them. This sort of thing from the article is just not something I would typically be trying to do in the normal course of shuffling data around.
Re:Why does a = a[0] = [0] create a self-referential list in...
by klyrs on Thursday November 18, 2021 @05:50PM
(#29271617)
I mean, it generally looks like a terrible idea, so absent of malice to the reader (or code golf shenanigans) nobody would do this. Not a surprise that the behavior is surprising...
Re:Why does a = a[0] = [0] create a self-referential list in...
by londons_explore on Thursday November 18, 2021 @06:54PM
(#29272147)
It's fallout of the fact that assignment must be a statement, and cannot be an expression.
Eg. This is wrong in python, while it would be allowed in c-like languages
print(a=5)
Looking through the archives, it's a really interesting blog in general