반응형

문자열을 일정한 길이로 나누기 

1
2
3
4
5
6
seq='12312312312312'
length=3
map(''.join, zip(*[iter(seq)]*length))
 
# result
['123''123''123''123']
cs

 

1
2
3
4
5
6
seq='12312312312312'
length=3
[''.join(x) for x in zip(*[list(seq[z::length]) for z in range(length)])]
 
# result
['123''123''123''123']
cs

 

1
2
3
4
5
6
seq='12312312312312'
length=3
[seq[i:i+length] for i in range(0len(seq), length)]
 
# result
['123''123''123''123''12']
cs

 

참고 사이트

 

http://code.activestate.com/recipes/496784-split-string-into-n-size-pieces/

 

<출처> http://blog.naver.com/PostList.nhn?from=postList&blogId=tius1234&categoryNo=6&parentCategoryNo=6¤tPage=6

 

반응형

+ Recent posts