Write a Python Program to Add Space between Potential Words
The program is written in Python and performs the following steps:
- A list val is defined with two elements, "TutorJoes" and "ComputerEducations".
- An empty list res is created to store the final result.
- A for loop is used to iterate over the elements in the val list.
- For each element in the val list, a nested for loop is used to iterate over its characters.
- For each character, the program checks if it is an uppercase letter using the isupper() method.
- If the character is uppercase, a new empty list [] is appended to the t list.
- The current character is then appended to the last list in t.
- After the inner loop has finished, the t list is converted into a string using the join() method and stored in the res list.
- The final res list is printed to the console.
Source Code
val = ["TutorJoes", "ComputerEducations"]
print("Original list : " ,val)
res = []
for i in val:
t = [[]]
for ch in i:
if ch.isupper():
t.append([])
t[-1].append(ch)
res.append(' '.join(''.join(i) for i in t))
print("The space added list of strings : " , res)
Output
Original list : ['TutorJoes', 'ComputerEducations']
The space added list of strings : [' Tutor Joes', ' Computer Educations']