请查看以下代码。
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
运行此代码会将x更改为y的相同值。为什么会这样?我根本不碰x!这样的混乱!请帮忙。