Search code examples
pythonlistlist-comprehensiontext-analysis

Removing digits from list elements


I have a list of job titles (12,000 in total) formatted in this way:
Career_List = ['1) ABLE SEAMAN', '2) ABRASIVE GRADER', '3) ABRASIVE GRINDER']

How do I remove the numbers, parentheses, and spaces from the list elements so that I end up with this output:
Career_List_Updated = ['ABLE SEAMAN', 'ABRASIVE GRADER', 'ABRASIVE GRINDER']

I know that I am unable to simply remove the first three characters because I have more than ten items in my list.


Solution

  • Take advantage of the fact that str.lstrip() and the rest of the strip functions accept multiple characters as an argument.

    Career_List_Updated =[career.lstrip('0123456789) ') for career in Career_List]