Avdhan Tyagi
Avdhan Tyagi

Reputation: 9

Convert string input into integer list in just one line of code in python

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]

Upvotes: 0

Views: 561

Answers (2)

user16836078
user16836078

Reputation:

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)

Upvotes: 0

scarf
scarf

Reputation: 332

there's also list comprehension

[int(n) for n in input().split(",")]

Upvotes: 4

Related Questions