I am currently attempting to create a list of ranges for letters in my program. I have done this through having a temp variable 'censorRange' to grab the range for an instance, then appending that variable to a 'censors' variable to be returned at the end of the function.
The issue is that when I change the 'censorRange' variable it also changes elements in the 'censors' variable. As an example: Initially, 'censorRange' = [10,15], and 'censors' = [[10,15]]. When I debug the program when 'censorRange' goes from '[10,15]' to '[17,23]' then 'censors' will also go to [[17,23]]. Then at the end of the program censors will give me [[17,23],[17,23]] instead of [[10,15],[17,23]].
Why does this occur, and how can I fix the problem? I have attached the code I have been using below. If you have any suggestions please do tell me, I have been getting frustrated over this for a while now. Thank you in advance.
Code:
censors = []
censorRange = [None, None]
for match in matches:
if((censorRange[0] != None) and (censorRange[1] != None)
and (match.span()[0] > censorRange[1])):
if(not lettersBetween(text, censorRange[1], match.span()[0], 5)):
censorRange[1] = match.span()[1]
censors.pop()
censors.append(censorRange)
censorRange[1] = match.span()[1]
else:
censors.append(match.span())
censorRange[0] = match.span()[0]
censorRange[1] = match.span()[1]
else:
censors.append(match.span())
censorRange[0] = match.span()[0]
censorRange[1] = match.span()[1]
return censors