0

Given a list

['R2', 'Y1-1', 'Y1-2', 'Y2-1', 'Y2-2', 'r']

i wish to remove all non-alphabetical characters and return the list in the form

['R', 'Y', 'Y', 'Y', 'Y', 'r']

Is there a way of doing this in python 3.6.3?

Mazdak
  • 105,000
  • 18
  • 159
  • 188
  • No this is completely impossible in Python... :). – Willem Van Onsem Oct 25 '17 at 18:00
  • start to write some code, like `for item in yourlist: ...` – RomanPerekhrest Oct 25 '17 at 18:01
  • I don't think the currently marked duplicate is correct. It so happens the example the OP gave is answered by that. However, he clearly states he wants all non-alphanumerical characters removed. Two such duplicates are [here](https://stackoverflow.com/questions/22520932/python-remove-all-non-alphabet-chars-from-string) and [here](https://stackoverflow.com/questions/1276764/stripping-everything-but-alphanumeric-chars-from-a-string-in-python) – Reti43 Oct 25 '17 at 18:03
  • Thanks. Solved using newlist = [item.rstrip('0123456-') for item in oldlist] print (newlist) – Paul Dunstan Oct 25 '17 at 18:10

0 Answers0