Class A:
def somefunction(self,somelist):
print(str(somelist)) #Prints ["1","#2","3","#4"]
b = B()
filterlist = b.remove_tagfromarray(somelist)
print(str(somelist)) #Prints ["1","3"] #<<<<<WHY IS THIS?!!!!!!
print(str(y)) #Prints ["1","3"]
remove_tagfromarray(x) takes in an array and returns an array without hashtags. However, after doing the code above it also alters the ORIGINAL array which was never operated on or referenced in the function called in the other class. I'm extremely confused. Even introducing a new variable doesn't seem to work.
Class A:
def somefunction(self,somelist):
savedarray = somelist
print(str(somelist)) #Prints ["1","#2","3","#4"]
b = B()
filterlist = b.remove_tagfromarray(somelist)
print(str(savedarray)) #Prints ["1","3"] WHY!?!?!?!?
print(str(filterlist)) #Prints ["1","3"]
as far as the function is concerned, it takes in the list as an argument, copies it to another "returnarray" variable, which is fiddled with until it is returned in the end. Mind you it works as I'm getting correct results, but somehow that function alters the original variable. Am I missing something here? Obviously somelist or savedarray (in the second example) should return the unaltered array.
def remove_tagfromarray(self,somelist,bannedchar="#"):
popque = []
popcount = 0
n=0
returnarray=somelist
for word in returnarray:
if (bannedchar in word)):
popque.append(n)
n+=1
for target in popque:
returnarray.pop(target-popcount)
popcount = popcount + 1
return returnarray