naz naz - 4 months ago 11
Python Question

converting input file to list

I have an input file text containing following entries

6.56
4.64
5.75
5.59
6.32
6.54
7.20
5.33


how can I convert this to list looking like following

[6.56,4.64,5.75,5.59,6.32,6.54,7.20,5.33]


pls help me

Answer
with open('filename.txt', 'r') as f:
    numbers = [float(x.strip()) for x in f]