May-08-2018, 04:08 PM
I have a module that takes 2 lists and creates a new list from them, but somehow it manages to change one of the input lists when I don't want it to:
def repeatAddCode(newList, oldList): # Version: 2.0 D Higgins 07/05/2018 # Input: a) A List of lists of the latest code numbers. # b) A List of lists of the original raw code numbers. # Function: If the last two numbers in a code from newList equal # the first two numbers in a code from oldList, add another # level of extended numbers. # Output: A new list of codes. returnList = [] # The position of the first column in a code row is stored as Lx[-2] # and the position of the last column in a code row is stored as Lx[-1]. for new in newList: newStart, newStop = new[-2], new[-1] for old in oldList[:]: oldStart, oldStop = old[-2], old[-1] if oldStart == newStart + 1 and old[oldStop - 1] == new[newStop] and old[oldStop - 2] == new[newStop - 1]: for entry in oldList: print '#', entry new[newStop + 1] = old[oldStart + 2] # This line changes oldList for entry in oldList: print '##', entry return returnListWhat am I doing wrong?