Is this possible? To delete everything in a string after any number?
Eg.:
some_text = "123 Text"
some_text_2 = "456 Foo"
I want to get only 123
and 456
without the space, and those numbers would be a random number
Is this possible? To delete everything in a string after any number?
Eg.:
some_text = "123 Text"
some_text_2 = "456 Foo"
I want to get only 123
and 456
without the space, and those numbers would be a random number
With little search on Stack Overflow.
For Python 2:
from string import digits
s = 'abc123def456ghi789zero0'
res = s.translate(None, digits)
# 'abcdefghizero'
For Python 3:
from string import digits
s = 'abc123def456ghi789zero0'
remove_digits = str.maketrans('', '', digits)
res = s.translate(remove_digits)
# 'abcdefghizero'
And add a replace
function to remove the space.