I have a list where each element is stored as a string
A = ['a', 'b', 'c', '100','200.6']
How can I extract only the numeric elements
[100, 200.6]
I cannot convert the elements using [float(i) for i in temp] as string elements cannot be converted to float. I need to retain the string elements as they are and just filter out the numeric elements.
Filterdef is_number(s): try: float(s) return True except ValueError: return False filter(is_number, A)this is cleaner than adding your own for loop