I am using input().split()
method to input elements in a list from a space separated single line input in python. However, I am unable to find a way to limit the inputs. As in if user is giving more than desired inputs in single line, is there any method to check that?
I read about assert method, but couldn't implement it correctly.
import numpy
m,n = map(int,input().split())
a = numpy.array([input().split() for i in range(n)], int)
print(a)
Input:
3 2
1 2 3 4 5
3 4 5 6 7
output:
[[1 2 3 4 5]
[3 4 5 6 7]]
I want the row should contain 3 elements per row and rest of the entries should be avoided/discarded without any errors. Please help. Expected Output:
[[1 2 3]
[3 4 5]]