👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I am writing a python MapReduce word count program. Problem is that there are many non-alphabet chars strewn about in the data, I have found this post Stripping everything but alphanumeric chars from a string in Python which shows a nice solution using regex, but I am not sure how to implement it
def mapfn(k, v):
print v
import re, string
pattern = re.compile("[W_]+")
v = pattern.match(v)
print v
for w in v.split():
yield w, 1
I"m afraid I am not sure how to use the library re
or even regex for that matter. I am not sure how to apply the regex pattern to the incoming string (line of a book) v
properly to retrieve the new line without any non-alphanumeric chars.
Suggestions?
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Python, remove all non-alphabet chars from string, check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Python, remove all non-alphabet chars from string
- Deutsch Python, remove all non-alphabet chars from string
- Français Python, remove all non-alphabet chars from string
- Español Python, remove all non-alphabet chars from string
- Türk Python, remove all non-alphabet chars from string
- Русский Python, remove all non-alphabet chars from string
- Português Python, remove all non-alphabet chars from string
- Polski Python, remove all non-alphabet chars from string
- Nederlandse Python, remove all non-alphabet chars from string
- 中文 Python, remove all non-alphabet chars from string
- 한국어 Python, remove all non-alphabet chars from string
- 日本語 Python, remove all non-alphabet chars from string
- हिन्दी Python, remove all non-alphabet chars from string
Munchen | 2023-03-26
Simply put and clear. Thank you for sharing. Python, remove all non-alphabet chars from string and other issues with string Python module was always my weak point 😁. I am just not quite sure it is the best method
Munchen | 2023-03-26
Maybe there are another answers? What Python, remove all non-alphabet chars from string exactly means?. Checked yesterday, it works!
San Francisco | 2023-03-26
Simply put and clear. Thank you for sharing. Python, remove all non-alphabet chars from string and other issues with io Python module was always my weak point 😁. Will use it in my bachelor thesis