0

Im wondering how to use python to read multiple pieces of data based on a given x

In my example I have x = 6 and then on the next line is the x amount of numbers. I want to be able to add it to an array/list or assign vars

6
1 2 4 8 10 11

Thank you

  • Please refer to the answer to ["How to read numbers from file in Python?"](https://stackoverflow.com/questions/6583573/how-to-read-numbers-from-file-in-python) –  Dec 18 '17 at 03:27
  • Possible duplicate of [How to read numbers from file in Python?](https://stackoverflow.com/questions/6583573/how-to-read-numbers-from-file-in-python) – JonathanDavidArndt Dec 18 '17 at 03:29
  • you can read all line, `split()` elements into list and get 6 elements from list. But you have only 6 elements in line so you get already list with 6 elements. – furas Dec 18 '17 at 03:40
  • So the `6` is kind of redundant? Which would be the point if truth? The `6` or the actual number of numbers? – Klaus D. Dec 18 '17 at 03:42
  • @KlausD. it can be challenge created for C/C++/Java which can read single number from file/stream so they may need this 6 to know when to stop reading data. – furas Dec 18 '17 at 03:53
  • 1
    @furas No, you would need the number in C or Java. File reading us not *that* bad in these languages. – Klaus D. Dec 18 '17 at 03:57
  • Do you want to add sum of those numbers or you want to add separate numbers? – Aaditya Ura Dec 18 '17 at 04:48

0 Answers0