input comma separated numbers, convert them into integer from string and then into integer list. this is what i came up with. is there any other way?
x = list(map(lambda x : int(x),(input()).split(",")))
print(x)
input : 1,2,3,55,66,714,78
output : [1, 2, 3, 55, 66, 714, 78]
Code-Apprentice
84k26 gold badges163 silver badges290 bronze badges
2 Answers 2
there's also list comprehension
[int(n) for n in input().split(",")]
Sign up to request clarification or add additional context in comments.
1 Comment
Farshid
List comprehension would be slightly faster than list(map())
If you don't mind a tuple, you can use eval
eval(input())
1,2,3,55,66,714,78
(1, 2, 3, 55, 66, 714, 78)
answered Aug 23, 2022 at 6:21
user16836078
Comments
lang-py
list(map(int, input.split(',')))lambdais not needed asmapmaps each element in the list toint. So answer your question, yes - there are many ways. But this is generally the most efficient.().