How to remove every non-alphabetic character in Python 3

python-3.x

Solution

According to 3.3 docs:

str.isalpha() Return true if all characters in the string are alphabetic and there is at least one character, false otherwise. Alphabetic characters are those characters defined in the Unicode character database as “Letter”, i.e., those with general category property being one of “Lm”, “Lt”, “Lu”, “Ll”, or “Lo”. Note that this is different from the “Alphabetic” property defined in the Unicode Standard.

So `isalpha()` includes all foreign accented characters as well as the acsii letters which you want.

The easiest way to isolate these may be to import `string.ascii_letters` which is a string of all lower and upper case ASCII letters, then

>>> from string import ascii_letters
>>> for element in chars:
>>>    if element in ascii_letters:
>>>        print(element)

Problem

I am coding the cesar chipper in Python 3, I have hit the point where I have to get rid of special characters in the chipper part. My current solution actually works but unwanted characters pass through: ``` chain = "abcàéÉç" listOfChain = list(chain) for element in listOfChain: if element.isalpha(): print(element) ``` The code above should only have print `abc` but `àéÉç` has passed. I only want to have `A-Z` and `a-z`, without `éèêëç` and so on... How to check if these characters are in the list ? So far `isalpha()` let those pass. Any other way to do that?

Original source