Search code examples
pythonlistmutation

Am I really mutating the list?


Say i'm given a list

lst1 = [1,2,3,4]
removed_item = lst1.pop()
lst1.append(removed_item)

I've changed the values for a temporary time, however I've reverted everything back to normal after the run. Is this considered mutating the list?


Solution

  • Yes you do, because you removed an item (mutating the list) and then re-append it (mutating the list... again).