Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to split string after certain character in python

If I have a string, lets just say, b a hello b Hi, how could I split the string by all bs AFTER the first occurrence of the letter a?

As in, it would return ["b a hello", "Hi"].

like image 279
Person Avatar asked May 17 '26 15:05

Person


1 Answers

This is documented here: str.rsplit()

sentence = 'b a hello b Hi'
sentence.rsplit('b', 1)
like image 159
Rambarun Komaljeet Avatar answered May 19 '26 06:05

Rambarun Komaljeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!