0

How do i receive multiple numbers from one input as a list of integers, then add this list to another list? To better explain, here's my last attempt:

list = []

for z in range (0, int(input())):
    list.append(input().split()) 

print(list[0])
print(list[1])
print(list)

with the inputs:

2
1 2
5 8

I get the following outputs:

['1', '2']
['5', '8']
[['1', '2'], ['5', '8']]

Now, what I’m looking for, is to receive those inputs somehow as integers, so the output for the same inputs would be:

[1, 2]
[5, 8]
[[1, 2], [5, 8]]

Thanks in advance for taking your time to help. I have tried to find the solution in the forum, but failed. Sorry if this has already been asked.

martineau
  • 119,623
  • 25
  • 170
  • 301
L. R
  • 1
  • 1
    Does this answer your question? [Get a list of numbers as input from the user](https://stackoverflow.com/questions/4663306/get-a-list-of-numbers-as-input-from-the-user). Third google result for searching *python input list of integer* BTW... – Tomerikoo Feb 23 '20 at 21:25
  • Does this answer your question? [Convert all strings in a list to int](https://stackoverflow.com/questions/7368789/convert-all-strings-in-a-list-to-int) – Mehdi Feb 23 '20 at 21:30

1 Answers1

0

You can use a list comprehension to convert the elements of the lists:

for z in range (0, int(input())):
    list.append([int(i) for i in input().split()])
quamrana
  • 37,849
  • 12
  • 53
  • 71