Skip to main content
1 of 2
flornquake
  • 1.6k
  • 11
  • 26

Python, 97

from itertools import*
s,n=input()
L=[]
i=0
exec"i+=1;L+=map(''.join,product(*[s]*i));"*n
print L

Input: 'ab', 3

Output:

['a', 'b', 'aa', 'ab', 'ba', 'bb', 'aaa', 'aab', 'aba', 'abb', 'baa', 'bab', 'bb
a', 'bbb']
flornquake
  • 1.6k
  • 11
  • 26