-3

How would you insert a whitespace into a string after every nth term. I need the output to still be a string, not a list.

This is what i would want it to look like:

message = ("xxxxxxxxxxxx")
output = ("xxxxx xxxxx xx") #E.g every 5 characters

*edit my question doesn't involve lists, only strings

Cassie.K
  • 1
  • 3

1 Answers1

0
>>> message = "xxxxxxxxxxxx"
>>>' '.join([message[i:i+5] for i in range(0, len(message), 5)])
'xxxxx xxxxx xx
Benjamin Hodgson
  • 42,952
  • 15
  • 108
  • 157
xiº
  • 4,605
  • 3
  • 28
  • 39