i've come across to a situation where my values are getting changed without my knowledge.
def randomizer(task):
maintask = task
x = 0
k = 1
while 1:
x += 1
if x > len(task):
break
if k == 0:
task.pop(x)
x -= 1
k = 1
else:
k = 0
#task.reverse()
#task = task + maintask
print("task ----- ", task)
print("maintask ----- ", maintask)
Above given is my python script. My expectation was "task" would be different from "maintask". But both gave same value to me. below given is the output.
task ----- [(9, 'CR12345'), (8, 'CR12346'), (3, 'CR63943'), (4, 'IM46667'), (2, 'THIS IS SE COND')]
maintask ----- [(9, 'CR12345'), (8, 'CR12346'), (3, 'CR63943'), (4, 'IM46667'), (2, 'THIS IS SE COND')]
I think this is the because "=" is working based on passing by reference. I need to pass the value which should not change after changing the parent variable ("task" here)