How to take in both input split by space(s) and by line(s)

Question:

for example I have this 2 inputs:

2 5 2

and:

2
5
2

How do I take all of them using the same code?

Asked By: yeet

||

Answers:

Read lines of input and split them until you get 3 total values.

inputs = []
while len(inputs) < 3:
    values = input().split()
    inputs.extend(values)

print(inputs) # this will print [2, 5, 2]
Answered By: Barmar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.