I have an object 'a' I want to convert it to a list such that it does not have any characters but numbers. Though, similar questions talk about list comprehensions but i was looking for a function method which will help me collect the numbers.
>>> a
['(', '0', ',', ' ', '1', ',', ' ', '2', ',', ' ', '3', ',', ' ', '4', ',', ' ', '5', ',', ' ', '6', ',', ' ', '7', ',', ' ', '8', ',', ' ', '9', ')']
Now, I was thinking about approaching this problem in two parts. First, i wanted to remove all ',' and ' '(blank spaces).
For this I coded :
>>> for x in a :
if x == ',' or x == ' ':
del x
This does not change the list at all.
Also, is there any way in which I can iterate through each object and check if it is a number and if it is not delete it. I think this would be much simpler.
Moreover, if there is a better way to resolve this, please suggest.