+ 1

Anyone help me?

I wrote a code to split a string by two characters. It is not working if the characters are not unique. How do I solve this? What if I had to split the string in terms of three characters? https://code.sololearn.com/ctrpi6r6g1bs/?ref=app

28th Sep 2021, 1:43 PM
Harsha S
Harsha S - avatar
8 Answers
+ 9
Harsha S , a bit late, but i did a try with your code and only correct it slightly. see the file with the code and the comments: https://code.sololearn.com/cXiQ97mXUyk5/?ref=app
29th Sep 2021, 5:38 PM
Lothar
Lothar - avatar
28th Sep 2021, 2:39 PM
A͢J
A͢J - avatar
+ 3
You can split the string by k characters https://code.sololearn.com/cuZiYnCRjE3e
28th Sep 2021, 2:44 PM
Gajendra Sonare
Gajendra Sonare - avatar
28th Sep 2021, 2:24 PM
Sacar
Sacar - avatar
+ 2
Harsha S In your code ,you are using x.index(i) which returns index of first charecter occurred index so if it have duplicates then it will always returns first occurence index. so that may the reason.
28th Sep 2021, 2:36 PM
Jayakrishna 🇮🇳
+ 2
thanks all
28th Sep 2021, 2:58 PM
Harsha S
Harsha S - avatar
29th Sep 2021, 3:37 AM
Shadoff
Shadoff - avatar