I have a list of lists as shown below, my goal is to get the numeric values from it. But the resultant output should be in similar format as of original list. so for example my list looks like this:
a_list = [['49', 'XT', '19.0', '93'],
['YTX', '124.0', '167 ', '77.0'],
['4 ', 'Y', '128,', '125,'],
['142.0', '120', '141.0'],
['12 ', '51.0'],
['0,', ' 82', '156'],
['82', '102.0'],
['94', 'YYZ', '178.0', '72'],
['120', 'YXT', '142', ' 134'],
['45,', '46', '79.0']]
My desired output is
b_list = [['49', '19.0', '93'],
['124.0', '167 ', '77.0'],
['4 ', '128,', '125,'],
['142.0', '120', '141.0'],
['12 ', '51.0'],
['0,', ' 82', '156'],
['82', '102.0'],
['94', '178.0', '72'],
['120', '142', ' 134'],
['45,', '46', '79.0']]
I wrote following code but it skips a lot of numbers plus format is not the same
final=[]
for i in a_list:
for num in i:
if num.isdigit():
final.append(num)
what I am doing wrong? and any way it could be done using list comprehension?