'Python how to make all number combinations [closed]

Python Python 3.10.2

How do I make all number combinations that I only use one of the list item in one combination?

for example:

list = ['258', '2478', '27', '2457', '578', '26', '26', '267']

22225222
52225222
82225222
24225222
27225222
28225222
...
88778667


Solution 1:[1]

Use recursion

def f(s):
    if len(s) == 1: return list(s[0])
    return [x+y for x in f(s[:-1]) for y in s[-1]]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yzhang