Because
x and y are just two names pointing to the same list in memory. When you modify one, the change reflects in both.Use
.copy() or slicing [:] if you want a separate list:y = x.copy()That way, you’re not changing the original but just making your own version.
