William Merritt
William Merritt

Reputation: 439

Read in multiple lines of input at once and store in list (python)

When given an input:

3
2 1
1 1 0

How would I take that input and store it as a list like so:

examList = [
      [3],
      [2,1],
      [1,1,0]
]

How do you identify the end user input if there any no specific indicators?

Currently have the following code:

examList = []
i = input()

while i != '':
    examList.append([int(s) for s in i.split()])
    i = input()

But I keep getting EOF errors when reading the last elements into the list.

Upvotes: 0

Views: 457

Answers (1)

arundeepak
arundeepak

Reputation: 594

examList = []
i = input()

while i != "":
    examList.append(list(map(int,i.split())))
    i = input()

print(examList)

it can be done in this way.

Upvotes: 1

Related Questions