Why is my program returning the same permutations multiple times?
Question: I have a simple code which I am using to try and get all combinations of 4
nucleotide bases, but only as sets of 3 because 3 nucleotides make up a codon.
I basically need to generate all possible permutations that can be made by the
4 bases a, c, t and g, and put them in chunks of three, however at first the
program seemed to work, and then as I looked at the result I realized it was
repeating the permutations 5 times.

I only need all permutations once and I am not sure how to change my code to
get this result. I am also very new to Python so I would really appreciate
simple talk and jargon in any answers, thank you!

This is the code:

    
    
    import itertools
    
    bases = ['a','c','t','g']
    for L in range(0, len(bases)+1):
      for subset in itertools.permutations(bases, 3):
        print(subset)
    

And the result I get looks right, but I just don't want it repeated 5 times:

    
    
    ('a', 'c', 't')
    ('a', 'c', 'g')
    ('a', 't', 'c').....
    


Answer: You're telling it to do it five times with that first `for L in range(0,
len(bases)+1):` line.

Without that it works fine.

    
    
    import itertools
    
    bases = ['a','c','t','g']
    for subset in itertools.permutations(bases, 3):
      print(subset)
    

