0

Any way to convert a string to a list where each character of the string is a separate item on the list? Using Python.

I'd like to do something along the lines of this: String = "this is a string" and after conversion the list would look like this: list = [t,h,i,s,i,s,a,s,t,r,i,n,g]

11th Jul 2018, 3:00 AM
Brendan Goodwin
Brendan Goodwin - avatar
5 Respuestas
+ 2
Brendan Goodwin Please keep this in mind a string in python is a list of characters. a = "thisisastring" print(a[1]) result: h
11th Jul 2018, 3:29 AM
ODLNT
ODLNT - avatar
+ 2
s = "This is a string" l = [] for x in s: if x.isalpha(): l.append(x) print(l)
11th Jul 2018, 4:37 AM
Paul
Paul - avatar
+ 1
String = "this is a string" list = [i for i in String] print(list) #o/p: It will give list of all each character of the string into a separate list
11th Jul 2018, 4:53 AM
Manoj Nagireddy
Manoj Nagireddy - avatar
0
string="this is a string" l=list(string) print(l) output= list of all the characters
11th Jul 2018, 3:53 AM
Pulkit Kamboj
Pulkit Kamboj - avatar
0
i think using the split function, it will help you. string = " this is a string" A = [] for i in string.split(): A.append (i) print A the problem about the split function is that,it will only split the the string if there is a space or a punctuation mark. that's what I have
11th Jul 2018, 4:38 PM
Sakhile Mbane
Sakhile Mbane - avatar