How do I copy only the values and not the references from a Python list?
        Posted  
        
            by wrongusername
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by wrongusername
        
        
        
        Published on 2010-03-16T23:25:19Z
        Indexed on 
            2010/03/16
            23:31 UTC
        
        
        Read the original article
        Hit count: 438
        
Specifically, I want to create a backup of a list, then make some changes to that list, append all the changes to a third list, but then reset the first list with the backup before making further changes, etc, until I'm finished making changes and want to copy back all the content in the third list to the first one. Unfortunately, it seems that whenever I make changes to the first list in another function, the backup gets changed also. Using original = backup didn't work too well; nor did using
def setEqual(restore, backup):
    restore = []
    for number in backup:
        restore.append(number)
solve my problem; even though I successfully restored the list from the backup, the backup nevertheless changed whenever I changed the original list.
How would I go about solving this problem?
© Stack Overflow or respective owner