Python 均匀地分割字符串

对于一个长序列,如何通过 Python 按照一定的长度均匀的进行分割?

>>> seq='ATGAACCACTCGCCGCTCAAGACCGCCTTGGCGTACGAATGCTTCCAGGACCAGGACAACTCCACGTTGGCTTTGCCGTCGGACCAAAAGATGAAAACAGGCACGTCTGGCAGGCAGCGCGTGCAGGAGCAGGTGATGATGACCGTCAAGCGGCAGAAGTCCAAGTCTTCCCAGTCGTCCACCCTGAGCCACTCCAATCG'
>>> len(seq)
200

具体方法如下:

>>> n=90
>>> for i in range(0, len(seq), n): print(seq[i:i+n])
...
ATGAACCACTCGCCGCTCAAGACCGCCTTGGCGTACGAATGCTTCCAGGACCAGGACAACTCCACGTTGGCTTTGCCGTCGGACCAAAAG
ATGAAAACAGGCACGTCTGGCAGGCAGCGCGTGCAGGAGCAGGTGATGATGACCGTCAAGCGGCAGAAGTCCAAGTCTTCCCAGTCGTCC
ACCCTGAGCCACTCCAATCG
>>> print([seq[i:i+n] for i in range(0, len(seq), n)])
['ATGAACCACTCGCCGCTCAAGACCGCCTTGGCGTACGAATGCTTCCAGGACCAGGACAACTCCACGTTGGCTTTGCCGTCGGACCAAAAG', 'ATGAAAACAGGCACGTCTGGCAGGCAGCGCGTGCAGGAGCAGGTGATGATGACCGTCAAGCGGCAGAAGTCCAAGTCTTCCCAGTCGTCC', 'ACCCTGAGCCACTCCAATCG']

image.png

my_string = 'abcdefghijklmnopqrstuvwxyz'
n = 3
result = [my_string[i:i+n] for i in range(0, len(my_string), n)]
print(result)