Jul-15-2020, 09:09 PM
I have a simple list of words and a function to sort those words.
It seems Python does not make a new list, just uses the new name as an alias for the original?
Is there some way to change this behaviour?
def sortAlpha(words):
words.sort()
return words;I get the words:def gettheWords():
textFile = pathToText + 'words'
textFileBody = open(textFile, 'r')
words = textFileBody.readlines()
textFileBody.close()
return words;
theWords = gettheWords()Then I do:sortedWords = sortAlpha(theWords)But when I look at my original list: theWords, that list is also sorted alphabetically. Why is that??
It seems Python does not make a new list, just uses the new name as an alias for the original?
Is there some way to change this behaviour?
