Strip non-alphabetical or non-alphanumeric characters in a string

less than 1 minute read

Strip non-alphabetical or non-alphanumeric characters in a string

Python characters have a function isalpha() and isalnum() which can be used to strip non-alphabetical or non-alphanumeric characters in a string.

s = ''.join(x for x in s if x.isalnum())
s = ''.join(x for x in s if x.isalpha())

Leave a comment