1

I am trying to solve a bioinformatics question. Basically, the user inputs a integer and I output all the possible permutations of A, C, G, T that are length of the imputed integer. The integer can be greater 4. For example:

If the user inputs 2, I will output:

['AA', 'AC', 'AG', 'AT', 'CA', 'CC', 'CG', 'CT', 'GA', 'GC', 'GG', 'GT']

If the user inputs 5, I will output:

['AAAAA', 'AAAAC', 'AAAAG', 'AAAAT', 'AAACA'.....'TTTGT', 'TTTTA', 'TTTTG', 'TTTTT']

Do you know how to make a function for this in python 2.7?

jay a
  • 434
  • 2
  • 5
  • 11

1 Answers1

3

You need product:

l = "ACGT"

from itertools import product    
print([''.join(s) for s in product(l, repeat=2)])
# ['AA', 'AC', 'AG', 'AT', 'CA', 'CC', 'CG', 'CT', 'GA', 'GC', 'GG', 'GT', 'TA', 'TC', 'TG', 'TT']
Psidom
  • 171,477
  • 20
  • 249
  • 286