You can use the built-in filter to get a filtered copy of the list.
>>> the_list = ['1','introduction','to','molecular',-8,'the','learning','module',5L] >>> the_list = filter(lambda s: not str(s).lstrip('-').isdigit(), the_list) >>> the_list ['introduction', 'to', 'molecular', 'the', 'learning', 'module']
The above can handle many objects using explicit type conversion. Since almost every Python object can be legally converted to a string, here filter takes a converted str copy for each member of the_list and checks if the string (minus any leading β-β character) is a numeric digit. If so, the member is excluded from the returned copy.
Built-in functions are very useful. Each of them is optimized for the tasks that they are intended for processing, and they will save you from new solutions.
user1877394
source share