I was trying to solve a problem that contains a code part similar to this. But whenever I tried to execute the script, it turns out to be an infinite loop. What is the reason for this issue and how can I solve it?
a=[1,2]
for i in a:
a.append(i)
print("Infinite")
I tried this program locally on my computer and Google Colab, but in both cases. But instead of appending values 1, 2 to list a
, it works differently.
I created a copy of a
by assigning z=a
and changed the structure of for
loop like this:
z=a
for i in z:
a.append(i)
But the issue remains the same: