It might be easier to break the DNA into a list of strings of 3 right away and iterate through the list.  I think you could probably eliminate one of the loops.