I have the following string:
"hello.world.foo.bar"
and I want to split (with the "."
as delimiter, and only want to get two elemets starting by the end) this in the following:
["hello.world.foo", "bar"]
How can I accomplish this? exist the limit by the end?
Use str.rsplit
specifying maxsplit (the second argument) as 1
:
>>> "hello.world.foo.bar".rsplit('.', 1) # <-- 1: maxsplit ['hello.world.foo', 'bar']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With