- 4
Input : johnVanWick Expected Output : John Van Wick. Can someone please tell the python code for this.
I
6 Réponses
+ 3
justanothercoder ,
there are 2 solutions that could be done:
- using regex
- iterating through the characters of the string to find the indexes of the uppercase characters. these can be used to separate the string.
happy coding
+ 2
justanothercoder as mentioned there are some different ways to approach but regex is one of the easier ways ..
https://code.sololearn.com/cOOzNd5wBwgV/?ref=app
+ 2
(regex should be the preferred version), but a version without regex could work like this:
https://code.sololearn.com/cqvCDoRxaAva/?ref=app
+ 1
show your code first
+ 1
Below is the function i have written. Any suggestions for improvement
def capandspace(txt):
new_txt = new_txt = [s for s in re.split("([A-Z][^A-Z]*)", txt) if s]
new_txt = " ".join(new_txt)
new_txt = new_txt[0].upper() + new_txt[1:]
return new_txt