strip all non-alphanumerics or all non-letters from a string in python
March 16th, 2010 by Lawrence David
to strip all the non-letters from a python string named ‘my_str’, you can use the following one-liner:
”.join([c for c in my_str if c.isalpha()])
to strip all the non-alphanumeric characters from that python string, use the slightly modified:
”.join([c for c in my_str if c.isalnum()])