Take a look at the following code.
import random
devicelist = ['a','a','a','a','a']
def generateconfig(tempconfiguration):
global devicelist
indexpositionzero = []
indexpositionone = []
for index in range(len(devicelist)):
if tempconfiguration[index] == 1:
indexpositionone.append(index)
else:
indexpositionzero.append(index)
if len(indexpositionone) >= 3:
godown = True
elif len(indexpositionone) == 0:
godown = False
else:
godown = random.randrange(0,2,1)
if godown == True:
index = random.randrange(0,len(indexpositionone),1)
tempconfiguration[indexpositionone[index]] = 0
if godown == False:
index = random.randrange(0,len(indexpositionzero),1)
tempconfiguration[indexpositionzero[index]] = 1
return tempconfiguration
x = [1,0,1,0,1]
y = generateconfig(x)
print x
print y
Running this code will change x to the same value of y. Why is this happening? I'm not touching x at all! Such confuse! Please help.