Skip to content

Instantly share code, notes, and snippets.

@Paulius-Maruska
Last active August 29, 2015 14:23
Show Gist options
  • Save Paulius-Maruska/288bc6528f0c732ba032 to your computer and use it in GitHub Desktop.
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.
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