Tell me, please, how can I enter the required number of values ​​in the list through a space? For example, in C ++ it is done like this:

for(int i = 0; i < N; i++) cin >> array[i]; 

And in Python, I came only to this:

array = list(map(int, input().split()))

But in this case there are no restrictions.

    2 answers 2

     In [1]: N = 5 In [2]: arr = list(map(int, input().split()[:N])) 1 2 3 4 5 6 7 In [3]: arr Out[3]: [1, 2, 3, 4, 5] 

    If I understood correctly.

    • Oooh, thank you) - KnowNamed September

    Almost the same as your example in C ++, N is the number of values.

     array = [] for _ in range(N): array.append(int(input())) 
    • If you enter values ​​through the space, then throw an error. And I need it through the space) - KnowNamed September