- 4

Input : johnVanWick Expected Output : John Van Wick. Can someone please tell the python code for this.

I

31st Mar 2022, 12:38 PM
justanothercoder
justanothercoder - avatar
6 Respostas
+ 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
31st Mar 2022, 2:49 PM
Lothar
Lothar - avatar
+ 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
31st Mar 2022, 6:43 PM
BroFar
BroFar - avatar
+ 2
(regex should be the preferred version), but a version without regex could work like this: https://code.sololearn.com/cqvCDoRxaAva/?ref=app
1st Apr 2022, 10:52 AM
Lothar
Lothar - avatar
+ 1
show your code first
31st Mar 2022, 12:39 PM
NonStop CODING
NonStop CODING - avatar
+ 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
1st Apr 2022, 10:31 AM
justanothercoder
justanothercoder - avatar