lundi 13 novembre 2017

Removing from a list without affecting a dummy variable

 from random import choice

inputs=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0']
func={}
code=""
z=len(inputs)
x=z-1
temp=inputs
while x>=0:
    y=choice(temp)
    print(str(x)+"   "+inputs[x]+"   "+y)
    func[inputs[x]]=y
    code=code+inputs[x]+y
    del temp[x]
    x=x-1
    print(temp)
    print(inputs)

Why does this code not asign every element of inputs to a unique and random element of inputs(as the temp dummy set)? it seems to delete items from both temp and inputs when only told to delete items from the dummy set.

Thanks for any help.




Aucun commentaire:

Enregistrer un commentaire