You are passing a reference to a container object to your listxgcd
function and the function retrieves elements from that container using pop
. This is not a scope issue, simply the fact there you are operating directly on the container you have passed to the function.
If you don't want the function to modify the container, make a copy of it:
import copy
def listxgcd( Ain ):
A = copy(Ain)
...
Or better, access the elements using indexing, if the container allows it:
...
g,s,t=xgcd(A[0],A[1])
...
for i in range(2,len(A)):
g,s,t=xgcd(g,A[i])
...