Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嘿伙计们,我有一个简单的问题。
如何将任意长度的字符串切成相等的部分
即 AGTTGTCGAGGTTGCGATTTATTGGGTGCGAGT 由 3 成
AGT TGT CGA GGT TGC GAT TTA TTG GGT GCG AGT
?
>>> s = 'AGTTGTCGAGGTTGCGATTTATTGGGTGCGAGT' >>> n = 3 >>> [s[i:i+n] for i in xrange(0, len(s), n)] ['AGT', 'TGT', 'CGA', 'GGT', 'TGC', 'GAT', 'TTA', 'TTG', 'GGT', 'GCG', 'AGT']