Dealing with mixed datatypes [closed]

On taking the input 1,2,3,4,5 initially python will consider it as a string datatype,

But if we try to convert the numbers to integer using int() we’ll encounter another problem as a commas cannot be converted into integer format

What will be the most appropriate way to convert the numbers into integer and keep the commas in the string format itself

Note: input cannot be changed in anyways

Answer

try this:

list(map(int, input().split()))

Output:

# input : 1 2 3 4 5
[1, 2, 3, 4, 5]

Or:

str_num = "1,2,3,4,5"
list(map(int, str_num.split(',')))

Output:

[1, 2, 3, 4, 5]