slice - Slicing in Python(Not Duplicate, Slicing for Translation) -
this question has answer here:
- how split list evenly sized chunks? 52 answers
- split string every nth character? 15 answers
hey guys have simple question.
how slice string of length equal parts
ie agttgtcgaggttgcgatttattgggtgcgagt 3 into
agt tgt cga ggt tgc gat tta ttg ggt gcg agt
?
>>> s = 'agttgtcgaggttgcgatttattgggtgcgagt' >>> n = 3 >>> [s[i:i+n] in xrange(0, len(s), n)] ['agt', 'tgt', 'cga', 'ggt', 'tgc', 'gat', 'tta', 'ttg', 'ggt', 'gcg', 'agt']
Comments
Post a Comment