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
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
with open('filename.txt', 'r') as f:
numbers = [float(x.strip()) for x in f]
You could directly read it from the file by readlines (assuming one value on each line) and convert it to float.
values = open('filename.txt', 'rb').readlines()
values = [float(value.strip()) for value in values]
Say you have those values in a file named values.txt
, you could try the following:
values = []
with open('values.txt', 'r') as f:
values = [line.strip() for line in f]