str = 'ATGGTGCATCTGACTCCTGAGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGG' for i, c in enumerate(str): if i%5 == 4: print c else: print c,
import re str = 'ATGGTGCATCTGACTCCTGAGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGG' for c in re.split(r'(.{5})', str): print c