Using the default CSV module
Demo:
import csv
with open(filename, "r") as infile:
reader = csv.reader(infile, delimiter=' ')
OutputList = [map(float, list(i)) for i in zip(*reader)]
print(OutputList)
Output:
[[1.0, 2.0, 3.0, 4.0, 5.0], [0.0, 0.0, 0.0, 0.0, 0.0], [5.0, 4.0, 3.0, 2.0, 1.0]]
OR
You can make use of this too as given-below:
from itertools import izip_longest
import csv
with open(filename, "r") as infile:
reader = csv.reader(infile, delimiter=' ')
OutputList = [map(float, [j for j in list(i) if j is not None]) for i in izip_longest(*reader)]
print(OutputList)