I have two characters, for example:
a = \'a\'
b = \'b\'
And I need to find all possible combinations of those two characters that will make a s
itertools.product is what you want here:
>>> from itertools import product
>>> a = 'a'
>>> b = 'b'
>>> N = 3
>>> lst = [a, b]
>>> [''.join(x) for x in product(lst, repeat = N)]
['aaa', 'aab', 'aba', 'abb', 'baa', 'bab', 'bba', 'bbb']
Which can also be written with a triple nested list comprehension:
>>> [x + y + z for x in lst for y in lst for z in lst]
['aaa', 'aab', 'aba', 'abb', 'baa', 'bab', 'bba', 'bbb']