I am trying to get Python to allow me to insert a space at regular intervals (every 5th character), in a string. This is my code:
str1 = "abcdefghijklmnopqrstuvwxyz"
list1 = []
list2 = []
count = 3
space = " "
# converting string to list
for i in str1:
list1.append(i)
print(list1)
# inserting spaces
for i in list1:
mod = count%6
count = count + 1
if mod == 0:
list1.insert(count,space)
count = count + 1
#converting back to a string
list2 = "".join(list1)
print(str(list2))
however it groups the first section together as 7. Can anyone help me fix this?