Далее используются только два вложенных цикла for
from itertools import product as prod
def consecutive_combos(a):
" Generates consecutive ombinations of items in list "
return [a[i:j] for i in range(len(a)) for j in range(i+1, len(a)+1)]
num = [1, 2, 3]
alpha = ['a', 'b', 'c']
# Generates product of sequences
result = [x + y for x, y in prod(consecutive_combos(num), consecutive_combos(alpha))]
print(result)
Выход
[[1, 'a'], [1, 'a', 'b'], [1, 'a', 'b', 'c'], [1, 'b'], [1, 'b', 'c'], [1, 'c'], [1, 2, 'a'], [1, 2, 'a', 'b'], [1, 2, 'a', 'b', 'c'], [1, 2, 'b'], [1, 2, 'b', 'c'], [1, 2, 'c'], [1, 2, 3, 'a'], [1, 2, 3, 'a', 'b'], [1, 2, 3, 'a', 'b', 'c'], [1, 2, 3, 'b'], [1, 2, 3, 'b', 'c'], [1, 2, 3, 'c'], [2, 'a'], [2, 'a', 'b'], [2, 'a', 'b', 'c'], [2, 'b'], [2, 'b', 'c'], [2, 'c'], [2, 3, 'a'], [2, 3, 'a', 'b'], [2, 3, 'a', 'b', 'c'], [2, 3, 'b'], [2, 3, 'b', 'c'], [2, 3, 'c'], [3, 'a'], [3, 'a', 'b'], [3, 'a', 'b', 'c'], [3, 'b'], [3, 'b', 'c'], [3, 'c']]