+ 4
How to convert each item of a number or a string into an item of a list
Lyk....123 to [1,2,3]
6 ответов
+ 6
For string just do:
my_list=list(string)
For numbers first convert number to string.In your example:
my_list=list(str(123))
+ 17
Let the string be str1='hello' and declare a list lst=[]
Then run a loop for all string elements like this -
for a in str1:
And then append the individual element of string to the list like this -
lst.append(a)
Hope this helps !!!
+ 13
Cbr✔[exams] But I think according to your method, there will a single element 'hello23d' in the list. But we want the output as each character or number as a single element.
So list should be ['h','e','l','l,'o'].
+ 13
Yup, that would work 👍