123 132 213 231 312 321 How to get all permutations as a seperate numbers?
Asked
Active
Viewed 1,161 times
-1
-
1Welcome, It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the [FAQ] and [ask]. – MooingRawr Aug 28 '18 at 17:42
-
1Look at `itertools.permutations`. – PM 2Ring Aug 28 '18 at 17:42
-
With [**`itertools.permutations`**](https://docs.python.org/2/library/itertools.html#itertools.permutations) – Willem Van Onsem Aug 28 '18 at 17:43
-
`for i in __import__("itertools").permutations('123'): print int(''.join(i))` – game0ver Aug 28 '18 at 17:44
1 Answers
0
Convert to a string with str()
, use itertools.permutations
to get the permutations, finally use a list-comprehension to format the result:
[int(''.join(p)) for p in itertools.permutations('123')]
#[123, 132, 213, 231, 312, 321]

Joe Iddon
- 20,101
- 7
- 33
- 54