I want to do nested loops with n times, this n is an variable and can be provided by function or input methods. In order to do this, I have to write lots of if..elif blocks depend on size of n, does anybody have good strategies to handle this task? The codes (for combination of 4 letters problem) I used are as follows:
def charCombination(n):
patList = []
s = 'ATCG'
if n == 1:
for i in s:
patList.append(i)
elif n == 2:
for i in s:
for j in s:
patList.append(i+j)
elif n == 3:
for i in s:
for j in s:
for k in s:
patList.append(i+j+k)
...
return patList