I have a list of numbers [1,2,3,4,5]. I would like to make a list, containing different permutations of [1,2,3,4,5] (i.e it would be a list of lists).
For example, I want something like [[1,4,5,3,2], [3,1,4,5,2],[ 5,1,2,4,3]].
import random
from random import shuffle
superlist = []
littlelist = [1,2,3,4,5]
for i in range(1, 4):
random.shuffle(little_list)
superlist.append(little_list)
print(superlist)
This outputs
[[2, 5, 4, 3, 1], [2, 5, 4, 3, 1], [2, 5, 4, 3, 1]]
So within my for loop, the 'random shuffle' produces the same thing. I tried time seeding it, but there was the same problem.
Aucun commentaire:
Enregistrer un commentaire