how many numbers can we generate from n digit? For example: from 1,2,3, we can generate 1,2,3,12,13,21,....321. And how can we generate a list containing those numbers in python?
Asked
Active
Viewed 63 times
1 Answers
0
Inefficient solution.
l=[1,2,3]
from itertools import permutations
for i in range(1, len(l)+1):
print [k for k in permutations(l, i)]
Output:
[(1,), (2,), (3,)]
[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]

vks
- 67,027
- 10
- 91
- 124