Skip to content

Latest commit

 

History

History
8 lines (6 loc) · 313 Bytes

strip-non-alphabetical-or-non-alphanumeric-characters-in-a-string.md

File metadata and controls

8 lines (6 loc) · 313 Bytes

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