python 3.4 - How do I filter a string for alphabetical characters? -


This is only giving me the first word in a string, which I need to return without numbers:

  Def striponon liter (estring): words = [] aString = aString.lower () for word in aString: if word.isalpha () or word.isspace (): words.append (word) print (Word) return '' (word) def main (): myString = '' 'Planes and 12 cars.' '' ['Planes,' 'and', 'car'] ", but" me "['' '' '' ' , '', '', '', '', 'P', 'L', 'A', 'N', 'E', 'S', etc. What am I doing wrong?   

After you aString = aString.split () , aString There is a list of words, none of these is empty space, if you remove that line, then you should be okay:

  def stripenon liter (astringe): a Otherwise, in the four in Estring: if char.isalpha () or char.isspace (): Answer = = Answer to the four returns  

Of course, this requires a lot of string extra , Which is disabled. Therefore, you may be more interested in using it:

  def stripNonLetters (aString): answer = [] in a string around: if char.isalpha ( ) Or char.isspace (): Answer .append (char) Return '' .join (answer)  

Comments