Created
August 25, 2013 00:18
-
-
Save hidsh/6331143 to your computer and use it in GitHub Desktop.
Python: 文字列を文字数で分割する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_str(s, n): | |
"split string by its length" | |
length = len(s) | |
return [s[i:i+n] for i in range(0, length, n)] | |
if __name__ == '__main__': | |
print(split_str('qwertyuiop', 2)) | |
print(split_str('qwertyuiop', 3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['qw', 'er', 'ty', 'ui', 'op'] | |
['qwe', 'rty', 'uio', 'p'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment