May-17-2020, 09:03 AM
You were on the right lines with rstrip. Instead use rsplit(), which takes two arguments. A delimiter and a maxsplit.
result = url_.rsplit('.', 1)[0]It doesn't matter how many '.' you have at the front of the string, it will only every remove anything after the last '.':
Output:>> a = "wikipedia.com"
>> print(a.rsplit(".", 1)[0])
>> wikipedia
>> a = "en.wkikipedia.com"
>> print(a.rsplit(".", 1)[0])
>> en.wkikipedia
>> a = "en.something.somethingelse.wikipedia.com"
>> print(a.rsplit(".", 1)[0])
>> en.something.somethingelse.wikipedia