You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we make a list and (attempt to) copy it then modify in place, we can cause all sorts of trouble:
odds = [1, 3, 5, 7]
primes = odds
primes: [1, 3, 5, 7, 2]
odds: [1, 3, 5, 7, 2]
This is because Python stores a list in memory, and then can use multiple names to refer to the same list. If all we want to do is copy a (simple) list, we can use the list function, so we do not modify a list we did not mean to:
The lesson does mention that this method of copying a list only works for simple lists. Much more detail than that likely dives too deeply into esoteric programming concepts not appropriate for the novice programmer audience that Software Carpentry targets. Given that the lesson calls out using list() to copy simple lists, I expect that instructors can tailor their message to specific audiences and mention deep copies if it seems that a particular class is ready to dive that deep.