Feed on
Posts
Comments

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()])


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS