By PeetZ


2015-10-27 21:37:45 8 Comments

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 comments

@John Gordon 2015-10-27 21:41:42

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

Related Questions

Sponsored Content

29 Answered Questions

[SOLVED] Finding the index of an item given a list containing it in Python

  • 2008-10-07 01:39:38
  • Eugene M
  • 3655199 View
  • 3005 Score
  • 29 Answer
  • Tags:   python list indexing

27 Answered Questions

[SOLVED] How do I check if a list is empty?

  • 2008-09-10 06:20:11
  • Ray Vega
  • 2671180 View
  • 3234 Score
  • 27 Answer
  • Tags:   python list

16 Answered Questions

[SOLVED] How to clone or copy a list?

63 Answered Questions

[SOLVED] Calling an external command from Python

7 Answered Questions

[SOLVED] How do I get the number of elements in a list?

  • 2009-11-11 00:30:54
  • y2k
  • 3202998 View
  • 1888 Score
  • 7 Answer
  • Tags:   python list

40 Answered Questions

[SOLVED] How to make a flat list out of list of lists?

21 Answered Questions

[SOLVED] How do I list all files of a directory?

  • 2010-07-08 19:31:22
  • duhhunjonn
  • 3982385 View
  • 3474 Score
  • 21 Answer
  • Tags:   python directory

25 Answered Questions

[SOLVED] How do I concatenate two lists in Python?

22 Answered Questions

[SOLVED] How do you read from stdin?

  • 2009-09-20 05:48:07
  • tehryan
  • 1552529 View
  • 1417 Score
  • 22 Answer
  • Tags:   python stdin

20 Answered Questions

Sponsored Content