I have a problem to be solved and I would appreciate if anyone can help. I want to generate all possible two-letters string from the given sequence. For example from string ‘ACCG’, I want to generate a list of [AA, CC, GG, AC,CA,AG,GA,CG,GC].
Does anyone have an idea how I can do that ?
>Solution :
An efficient solution can be coded using itertools module
CODE
import itertools
string = 'ACCG'
num = 2
combinations = list(itertools.product(string, repeat=num))
result = [*set([''.join(tup) for tup in combinations])]
print(result)
OUTPUT
['CG', 'GG', 'GC', 'GA', 'AG', 'AA', 'CC', 'AC', 'CA']