0
how to take a integer N as input from user and after that take N spaced integers as input and store them in a single list
print([int(x) for x in input().split()]) takes unlimited input I want exact N inputs
4 Answers
+ 2
[int(input()) for i in range(int(input()))]
+ 1
@HonFu I want to take spaced input...your code doesnt satisfy the condition
+ 1
Split also takes a maxsplit argument to define how many cuts you make.
... .split(maxsplit=...)
That will still lead to crap values.
For n being 3 you could use a maxsplit n, but then you'll get something like:
['5', '6', '7', '8 9 10']
So you'd still throw away something.
You could also take the full split, but only execute code for n elements.
for i in range(n):
...
0
Wonderful this slicing solution is working Alexandr
More than N numbers won't be inserted in the list right??