I would like to get all possible combinations of the letters in a string with length k. I know there are many posts on this but I have a little twist k is larger than the length of the string.
This is what I have so far, its simple and works if k <= len(string):
string = 'ABCD'
permutations = ["".join(x) for x in itertools.permutations(string, k)]
results if k = 4:
['ABCD', 'ABDC', 'ACBD', 'ACDB', 'ADBC', 'ADCB', 'BACD', 'BADC', 'BCAD', 'BCDA',
'BDAC','BDCA', 'CABD', 'CADB', 'CBAD', 'CBDA', 'CDAB', 'CDBA', 'DABC', 'DACB',
'DBAC', 'DBCA', 'DCAB', 'DCBA']
This works as expected. However, I would like all possible combinations of these four letters with k > len(string).
An example answer I would like would be:
string = 'AB'
k = 4
result = ['AAA,'ABB','AAB', 'ABA','BBB', 'BAA'.......]
Thanks in advance.