I have the code below. Basically, I want to take an array like ["appleBanana", "bananaFruit", "cherryBlossom"] and turn it into ["Apple Banana", "Banana Fruit", "Cherry Blossom"].
This is in Python.
Reproducible example:
typelist = ["appleBanana", "bananaFruit", "cherryBlossom"]
typelist2 = ['']
last_was_upper = True
counter = 0
for d in typelist:
for c in d:
if c.isupper():
if not last_was_upper:
typelist2[counter] += ' '
last_was_upper = True
else:
last_was_upper = False
typelist2[counter] += c
counter = counter + 1
print(typelist2)
Edit
For my actual code, this is the output I got
[' Advanced Algebra', ' Problem Solvingand Data Analysis', ' Basic Algebra', ' Problem Solvingand Data Analysis', ' Advanced Algebra', ' Advanced Algebra', ' Advanced Algebra', ' Problem Solvingand Data Analysis', ' Advanced Algebra', ' Problem Solvingand Data Analysis', ' Problem Solvingand Data Analysis', ' Problem Solvingand Data Analysis', ' Advanced Algebra', ' Problem Solvingand Data Analysis', ' Advanced Algebra', ' Advanced Algebra', ' Advanced Algebra', ' Advanced Algebra', ' Advanced Algebra', ' Problem Solvingand Data Analysis']
Notice how some of them have a space before the phrase while others have no space between the letters. My desired outcome is simply "Advanced Algebra" (with respective fields obviously). How can I remove the space in the beginning and add a space in the middle for all of them?