I have a list:
rows=['1\t0.00032822\n', '2\t0.00029311\n', '3\t0.0002048\n',...]
and i want to have a list with the numbers only:
['0.00032822', '0.00029311', '0.0002048',...].
Something like:
list = [sliceAppropiate(x) for x in rows]
Use a list comprehension:
>>> rows = ['1\t0.00032822\n', '2\t0.00029311\n', '3\t0.0002048\n']
>>> [r.split()[1] for r in rows]
['0.00032822', '0.00029311', '0.0002048']
What this does is:
rows in turn,r,r into a list with split(), by cutting at whitespace (which can be spaces, tabs or newlines),float, and the square brackets around the listcomp (turning into a generator expression): sum(float(r.split()[1]) for r in rows)Here is a very simple code that do it for you:
list = []
for i in range(len(rows)): # from 0 to len(rows) - 1
list[i] = rows[i].split('\t')[1]
If need float numbers use float function:
float(rows[i].split('\t')[1])