Given a starter string, and a number of spaces needing to be added to a string, is there an easy way to do this? If the number of spaces is uneven spread, add spaces left to right.
This is what I've tried:
dividing space number with actual string spaces
div = spaces // (word_count - 1)
tokenize string
temp = st.split()
for i in range(len(temp)):
If first word just add the current word w/o spaces
if i == 0:
st = temp[0]
If first word just add the current word w/o spaces
else:
add div amount of spaces + original space to word
st = st + " "*div + " " +temp[i]
update our space count
space_count = space_count - div
space_count matches or is smaller than actual amount of spaces in string
if space_count <= word_count -1:
st = st.replace(" ", " ", space_count)
add an extra space, 'space_count' amount of times. This is where the problem is, it only replaces the first space_count amount of white spaces characters. Any tips on how to add the last spaces, or finding a better way to do this?
Here is an example:
"Algernon. Did you hear what I was playing, Lane?"
and given space_Count = 12, should give
Algernon. Did you hear what I was playing, Lane?
Edit: got it working!