1
votes

I want to put a number of floats I receive from stdin in a list. But using the following program only returns an object. How can I put the floats I receive in a list?

Input looks like this: 0.1 0.1 0.3 0.4 0.1 0.4 0.2 0.1 0.1 0.2 0.5 0.05 0.15 0.1 0.2 0.6 0.1 0.1 0.1 0.1 0.5 0.2 0.2 0.05 0.05

def main():
for line in sys.stdin:
    x= map(float, line.split())
    print (x)
main()
1

1 Answers

1
votes
for line in sys.stdin:
    myfloats = [float(x) for x in line.split()]