dimanche 24 avril 2016

Permutations of several lists in python efficiently

I'm trying to write a python script that will generate random permutations of several lists without repeating

i.e. [a,b] [c,d]
a, c
b,c,
a,d
b,d

I can generate every permutation using the following, however the result is somewhat non random:

for r in itertools.product(list1, list2):
        target.write("%s,%s" % (r[0], r[1])

Does anyone know a way i can implement this such that I can extract only 2 permutations, and they will be completely random but ensure that they will never be repeated?




Aucun commentaire:

Enregistrer un commentaire