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

5th Jan 2020, 12:42 AM
Leman Kirme
Leman Kirme - avatar
4 odpowiedzi
+ 2
[int(input()) for i in range(int(input()))]
5th Jan 2020, 1:15 AM
HonFu
HonFu - avatar
+ 1
@HonFu I want to take spaced input...your code doesnt satisfy the condition
5th Jan 2020, 1:23 AM
Leman Kirme
Leman Kirme - avatar
+ 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): ...
5th Jan 2020, 9:03 AM
HonFu
HonFu - avatar
0
Wonderful this slicing solution is working Alexandr More than N numbers won't be inserted in the list right??
5th Jan 2020, 2:16 AM
Leman Kirme
Leman Kirme - avatar