I want to fill a list with n integers in a single line, I tried this but how to add a limit of n?
L=[int(x) for x in input().split()]
I want to fill a list with n integers in a single line, I tried this but how to add a limit of n?
L=[int(x) for x in input().split()]
zip
stops on the shortest sequence. You can use that to limit how many split items you consume.
limit = 5
L=[int(x) for _,x in zip(range(limit), input().split(maxsplit=limit))]
Just slice at the limit.
limit = 3
L = [int(x) for x in input().split()][:limit]
Does this work?
n=int(input())
while True:
L=[int(x) for x in input().split()]
if len(L)==n:
break