Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strip Numbers From String in Python [duplicate]

Tags:

python

nltk

Is there an efficient way to strip out numbers from a string in python? Using nltk or base python?

Thanks, Ben

like image 774
ben890 Avatar asked May 19 '15 00:05

ben890


People also ask

What does Strip () split () do in Python?

If the developer specifies a set of characters as an argument to the strip() function, it removes those characters or symbols from the beginning and the end of the string to return the original string. What is split and strip Python? Python split() function breaks up a string to return the list of all strings.


1 Answers

Yes, you can use a regular expression for this:

import re
output = re.sub(r'\d+', '', '123hello 456world')
print output  # 'hello world'
like image 187
14 revs, 12 users 16% Avatar answered Sep 27 '22 15:09

14 revs, 12 users 16%