I find myself doing this pattern a lot:
new_url = season_url.split('cid=')[0] + 'cid='
Is there a more pythonic way to do this?
Something like this?
def truncate_after(s, needle):
partition_pos = s.index(needle)+len(needle)
return s[:partition_pos]
It could also return the other part if you wanted both pieces.
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