PeetZ
PeetZ

Reputation: 89

Put integers from stdin in list

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()

Upvotes: 1

Views: 363

Answers (1)

John Gordon
John Gordon

Reputation: 33335

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

Upvotes: 1

Related Questions