Let's say the number is 123.
Then the statement:
[int(''.join(x)) for x in permutations(list(str(123)))]
will create a sorted list of all possible numbers using '1','2' and '3'. which is, [123, 132, 213, 231, 312, 321]
What it is doing
However, of course, you need to
import permutations from itertools.
so, the generalized version would be:
from itertools import permutations [int(''.join(x)) for x in list(permutations(list(str(n))))]
Python is fun. Isn't it?