While creating a quiz game I came across this weird discovery, when using .pop() method on a list that is a copy of another list, the original list's items are removed. I wrote this simple code to let you better understand what I mean:
myList = [1, 2, 3, 4]
myListDup = myList
print("{}\n{}".format(myListDup, myList))
for i in range(len(myList)):
myListDup.pop()
print("{}\n{}".format(myListDup, myList))
As this shows, after using .pop() to remove all the elements from myListDup, myList is empty aswell (I know there are other ways to remove elements, but I need to use .pop() in my original program) Are there ways to avoid this?