0

I'm very new at python and maybe this is a possible duplicate, but I didn't found anything near these topic.

I want to shuffle an int list in each possible variant in python.

Example:

a = [2, 5, 8, 9]

Expected result:

variants = 
[
  [2, 5, 8, 9],
  [2, 5, 9, 8],
  [2, 9, 5, 8],
  [2, 9, 8, 5],
  [2, 8, 9, 5],
  [2, 8, 5, 9],
  [5, 2, 8, 9],
  ...
]

Anyone an idea, to do this very fast and efficent?

Thanks for helping me guys.

Søny
  • 109
  • 1
  • 7

1 Answers1

2

Just use itertools

itertools.permutations(a)
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173