mardi 24 novembre 2015

python, shuffle until lists are completely different

i want to ask how to shuffle, maybe in a while loop, until some lists are completely different?

#lists you want to shuffle
s1 = [1, 2, 3, 4]
s2 = [1, 2, 3, 4]
s3 = [1, 2, 3, 3]
s4 = [1, 2, 3, 4]

def mid_generator():

while True:
    random.shuffle(s1)
    random.shuffle(s2)
    random.shuffle(s3)
    random.shuffle(s4)

    # if ... all lists are different...:
         #break

return s1, s2, s3, s4

So that the number is only one time in row i and column j:

s1 = [3, 1, 2, 4]
s2 = [4, 2, 1, 3]
s3 = [2, 4, 3, 1]
s4 = [1, 3, 4, 2]

If i try long if-Statements with if s1[0] != s2[0] .... the output is wrong. Maybe you could help me.

Aucun commentaire:

Enregistrer un commentaire