0

Can you pls tell me how to put comma between the numbers in this code

Lst=[ ] Lst=[int(item) for item in input().split()] print(Lst) Example input=6738 Output:[6738] I want this :[6, 7,3,8]

15th Jan 2021, 1:50 PM
amir hosein kazazi
amir hosein kazazi - avatar
3 Answers
+ 3
The str.split() method splits the string where there are spaces. Example "6 7 3 8".split() will return ["6", "7", "3", "8"] Ao if the input was "6 7 3 8", your code will work. But if you want to make a list of each character in the string, use the list() function. Example list("6738") will return ["6", "7", "3", "8"] So in your code, replace `input().split()` with `list(input())`
15th Jan 2021, 2:06 PM
XXX
XXX - avatar
+ 2
Then just an additional to XXX, use list comprehension to convert each element to integer if the challenge wants each element of the list output to be an integer type [int(item) for item in list(input())] OR list(map(int, list(input()))
15th Jan 2021, 3:31 PM
noteve
noteve - avatar
0
Thank you
15th Jan 2021, 3:45 PM
amir hosein kazazi
amir hosein kazazi - avatar