Last active
August 29, 2015 14:23
-
-
Save Paulius-Maruska/288bc6528f0c732ba032 to your computer and use it in GitHub Desktop.
short python function to insert a space into a string every N characters.
This file contains hidden or 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 space(s, n): | |
"""inserts a space every n characters in string s | |
>>> space('0123456789', 3) | |
'012 345 678 9' | |
>>> space('0123456789', 4) | |
'0123 4567 89' | |
""" | |
return ' '.join(s[i:i+n] for i in range(0, len(s), n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment