0

私はこの文字列を持っています

str = CTGGCATAACAAGACAAAAACAAAAGCAATAAATGCTGAAAAAACAAAATGCCGTGATCGTTTGTAATACTGGAACATAGTCATGATGAATGAAGGTTTCTGAACCTGAAGAACGACCTGAAAAAGTCAAACCGCAAGAATATCACGACGCAGTGAACCAGAATAGCAACGACGAAAATGTCCAGGAAAAATCCTGGAGTCAGATTCAGGGTTATTCGTTAGTGGCAGGATTACGAAGCGTGGGGCACAGGAGATACATCTCCAGTAAGATGGCAACGTAATCGCGGGCTTCTTTTTTAAGATCAAAAGATTGCGGGGCAAAGAGCCAGTTTTCCATCAGGCCGGAAATATAGCCGCGCATAATAATTGCTGCGCGACGCGTCATTAAATCCGCAGGCAACATTTTCGCTTCAATACAATGTTTTAACGTTTGTTCTATACGGTCATAACTTTCCAGACAGAGATTACGTTGTGCCTGTTGCACAACAGCCATTTCTCCGACAAATTCGCATTTGTGGAATATAATCTCCATCAATAATCGACGCCGTTCTTCTGTCACCGTGGATTCAAGAACATGAATTAATATCTCTCTTAATACTGAGAGTGGATCGCCAGGGAATTTTGCCTGATACTCAAGCTCTAGTTCACCAATATTGGATTCTGACAGTTCCCAGATCTCACTGAACAAATCCGACTTGTCTTTAAAATGCCAGTAGATTGCACCGCGCGTAACGCCAGCTGCTTTTGCAATCTCGCCCAGCGAGGTGGATGATACCCCCTGCTGTGAGAAAAGACGTAGAGCCACATCGAGGATGTGTTGGCGCGTTTCTTGCGCTTCTTGTTTGGTTTTTCGTGCCATATGTTCGTGAATTTACAGGCGTTAGATTTACATACATTTGTGAATGTATGTACCATAGCACGACGATAATATAAACGCAGCAATGGGTTTATTAACTTTTGACCATTGACCAATTTGAAATCGGACACTCGAGGTTTACATA

この文字列を str[0:19] str[1:20] str[2:21] str[3:22] ..... などの複数の部分文字列に切り詰めて最後まで切り詰めたいと思います。

4

3 に答える 3

3

文字列スライスを使用します。

>>> strs = "CTGGCATAACAAGACAAAAACAAAAGCAATAAATGCTGAAAAAACAAAATGCCGTGATCGTTTGTAATACTGGAACATAGTCATGATGAATGAAGGTTTCTGAACCTGAAGAACGACCTGAAAAAGTCAAACCGCAAGAATATCACGACGCAGTGAACCAGAATAGCAACGACGAAAATGTCCAGGAAAAATCCTGGAGTCAGATTCAGGGTTATTCGTTAGTGGCAGGATTACGAAGCGTGGGGCACAGGAGATACATCTCCAGTAAGATGGCAACGTAATCGCGGGCTTCTTTTTTAAGATCAAAAGATTGCGGGGCAAAGAGCCAGTTTTCCATCAGGCCGGAAATATAGCCGCGCATAATAATTGCTGCGCGACGCGTCATTAAATCCGCAGGCAACATTTTCGCTTCAATACAATGTTTTAACGTTTGTTCTATACGGTCATAACTTTCCAGACAGAGATTACGTTGTGCCTGTTGCACAACAGCCATTTCTCCGACAAATTCGCATTTGTGGAATATAATCTCCATCAATAATCGACGCCGTTCTTCTGTCACCGTGGATTCAAGAACATGAATTAATATCTCTCTTAATACTGAGAGTGGATCGCCAGGGAATTTTGCCTGATACTCAAGCTCTAGTTCACCAATATTGGATTCTGACAGTTCCCAGATCTCACTGAACAAATCCGACTTGTCTTTAAAATGCCAGTAGATTGCACCGCGCGTAACGCCAGCTGCTTTTGCAATCTCGCCCAGCGAGGTGGATGATACCCCCTGCTGTGAGAAAAGACGTAGAGCCACATCGAGGATGTGTTGGCGCGTTTCTTGCGCTTCTTGTTTGGTTTTTCGTGCCATATGTTCGTGAATTTACAGGCGTTAGATTTACATACATTTGTGAATGTATGTACCATAGCACGACGATAATATAAACGCAGCAATGGGTTTATTAACTTTTGACCATTGACCAATTTGAAATCGGACACTCGAGGTTTACATA"
>>> substrings = [strs[i:i+19] for i in xrange(len(strs))]
>>> substrings
['CTGGCATAACAAGACAAAA', 'TGGCATAACAAGACAAAAA', 'GGCATAACAAGACAAAAAC',...]
于 2013-06-14T17:18:10.813 に答える
1
chopped_str = []
for i in range(0, len(str)-19):
   chopped_str.append(str[i:i+19])
于 2013-06-14T17:18:02.253 に答える