This is my first question on the forum and I'm also really new to Python, so maybe this doesn't make a lot of sense, but I'm just left wondering...
It's very related, but IMO this question Slicing a list in Python without generating a copy does not answer the question of how to slice a list in such a fashion that changing the slice would change the original?
Say, if I want to change only part of a list in a function and make sure that the function doesn't have access to all the members, how do I write this:
def myFunc(aList):
for i in range(0,len(aList)):
aList[i] = 0
wholeList = range(0,10)
partOfList = wholeList[3:6]
myFunc(partOfList)
so that the in the end wholeList
would be
[0, 1, 2, 0, 0, 0, 6, 7, 8, 9]
??
I guess this would work if the contents of wholeList
were mutable objects, but with numbers is the only way to have the myFunc
return the changed list and assign in the calling workspace?