[Solved] Python create all possible combinations from a integer [duplicate]


I guess this is what you are looking for:

num = 123
s = str(num)
[[x for x in i if x is not '' and ' '] for i in [list(s.partition(item)) for item in list(s+' ')]]

Output:

[['1', '23'], ['1', '2', '3'], ['12', '3'], ['123']]

You could also use tuples:

s = str(num)
[tuple([x for x in i if x is not '' and ' ']) for i in [list(s.partition(item)) for item in list(s+' ')]]

Output:

[('1', '23'), ('1', '2', '3'), ('12', '3'), ('123',)]

6

solved Python create all possible combinations from a integer [duplicate]