lundi 22 août 2016

python random shuffle while loop

I'm trying to fill lists with permutations of the same initial list. I don't understand why the following is not working.

parts = [[],[]]
while len(parts[-1]) < 2:
  newval = random.choice([[1,2,3,4],[5,6,7,8]])
  for part in parts:
    random.shuffle(newval)
    part.append(newval)

Expected result would be something like: [[[6,7,8,5],[1,3,4,2]],[[5,8,6,7],[4,2,3,1]]]




Aucun commentaire:

Enregistrer un commentaire