how do I remove all occurrences in a string up to the first space, so that:
strings = ["1234 zoocore", "4356 00's punk"]
becomes: ["zoocore", "00's punk"] ?
I have tried regex:
for s in strings:
new_s = re.sub(r'\d+','', s)
but that erases 00' as well, which I don't want.
You can use str.split with maxsplit parameter:
>>> strings = ["1234 zoocore", "4356 00's punk"]
>>> [s.split(None, 1)[1] for s in strings]
['zoocore', "00's punk"]
If you have strings that don't contain space you can use -1 as index:
>>> strings = ["1234 zoocore", "4356 00's punk", "rock"]
>>> [s.split(None, 1)[-1] for s in strings]
['zoocore', "00's punk", 'rock']
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