0

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.

2
  • Move print statement outside of while loop. I've executed this code and didn't face any such error. Commented Feb 25, 2018 at 19:34
  • Check if your IDE supports input() function.Check this one stackoverflow.com/questions/12547683/… Commented Feb 25, 2018 at 19:39

1 Answer 1

1
examList = []
i = input()

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

print(examList)

it can be done in this way.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.