1

I want to create an array out of an input so I use sys.stdin.readlines(). My inputs are multiple integers looking like this:

random number
random number
random number 
random number

However sys.stdin.readlines() creates an array and turns all these random numbers into strings. The array looks like this:

Array = ['random number\n','random number\n','random number\n','random number\n']

That is not what I want. I want the input to be turnt into an array but I still want the array entries to be integers.

I use python so the arrays I am talking about are actually lists.

Math Noob
  • 25
  • 1
  • 6
  • I do not really know. I see something I have not learned yet (raw_input) so by just looking at the other post no it would not help me fully. However somebody with more domain knowledge might see that differently. – Math Noob Jun 09 '20 at 10:30
  • well `raw_input` is simply a Python 2 function which is replaced with `input` in Python 3 – Tomerikoo Jun 09 '20 at 10:32

1 Answers1

1

You'll have to convert them into integers using a comprehension or something similar e.g. [int(x) for x in sys.stdin.readlines()]

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169