Nov-05-2020, 04:18 PM
N is a list and is therefore mutable.
In triangles() you hand back an object in line 4 (yield N), but then in line 5 you modify that object. If the caller didn't make a copy yet, their copy of the object is changed as well.
A simple change here would be to return a copy of the list so that the caller's object can't be modified later by the function.
In triangles() you hand back an object in line 4 (yield N), but then in line 5 you modify that object. If the caller didn't make a copy yet, their copy of the object is changed as well.
A simple change here would be to return a copy of the list so that the caller's object can't be modified later by the function.
yield list(N)