Home > Back-end >  how to take in input of every other line
how to take in input of every other line

Time:12-18

say there was an input like so:

3
33 2
44 4
55 5

I tried

n = int(input())

for i in range(n):
  n, m = map(int, input().split())

but since there is a space in between it doesn't work.

CodePudding user response:

Maybe use splitlines() instead of split()

CodePudding user response:

it's probably much easier to

  • take inputs until the input is empty instead of asking how many there will be in advance
  • use a comprehension map() to collect the values (though your map works fine for me! map(int, line.split()))
collection = []
while True:
    line = input()
    if not line.strip():
        break
    collection.append([int(x) for x in line.split()])
  • Related