0

How to enter list of given range of elements at a time,plz check description

L=[int(x) for x in input().split()] -->any number of integers intake But i want to take elements according to user requirement like L=[int(x) for x in range(6).input().split()]-->but its not working

26th Dec 2020, 6:09 PM
Krid Indu
Krid Indu - avatar
14 odpowiedzi
+ 1
As you want your L list to be int you can just add [:6] after split function in your solution L=[int(x) for x in input().split()[:6]]
26th Dec 2020, 7:06 PM
Sathish Kanna
Sathish Kanna - avatar
+ 2
if suppose you provide your input data may be we could get a clear understanding about the issue
26th Dec 2020, 6:56 PM
Sathish Kanna
Sathish Kanna - avatar
+ 1
the thing is you don't need a loop for this input. you can use a slice operation for this like L=input ().split()[:6]
26th Dec 2020, 7:01 PM
Sathish Kanna
Sathish Kanna - avatar
0
you mean like six different list of numbers?
26th Dec 2020, 6:35 PM
Sathish Kanna
Sathish Kanna - avatar
0
S,6 different integers in same list
26th Dec 2020, 6:41 PM
Krid Indu
Krid Indu - avatar
0
maybe you can try using two for loops like L=[[int(y) for y in input().split()] for x in range(6)]
26th Dec 2020, 6:43 PM
Sathish Kanna
Sathish Kanna - avatar
0
Iam getting error message
26th Dec 2020, 6:46 PM
Krid Indu
Krid Indu - avatar
0
what error message
26th Dec 2020, 6:47 PM
Sathish Kanna
Sathish Kanna - avatar
0
mylist = [int(input()) for x in range(6)] print(mylist) # or size = int(input()) mylist = [int(input()) for x in range(size)] print(mylist) You can also use an underscore instead of the 'x' above.
26th Dec 2020, 6:47 PM
rodwynnejones
rodwynnejones - avatar
0
Sathish Kanna once try to execute it
26th Dec 2020, 6:53 PM
Krid Indu
Krid Indu - avatar
0
rodwynnejones u haven't used split function
26th Dec 2020, 6:55 PM
Krid Indu
Krid Indu - avatar
0
I/p:-5 2 0 8 9 0 Ur approach is correct but it is showing EOF error
26th Dec 2020, 6:58 PM
Krid Indu
Krid Indu - avatar
0
Give example input.
26th Dec 2020, 7:00 PM
rodwynnejones
rodwynnejones - avatar
26th Dec 2020, 7:40 PM
Krid Indu
Krid Indu - avatar