0

Can split method of list be used to separate each alphabet of a word in the list? Or an alternate way to do it?

Hi, if I am writing a code where a user is to input a string, I can easily convert it into a list of separate words of that string by using split method. But what if I wanted to spilt the alphabets too? Is there a way to do it? Simply, what I want is to have user input a word (let's just say only one word) and have it's alphabets in a list separately. I don't have much creativity, so I learn only this way. Thanks for all the help in advance

12th Jul 2020, 6:59 PM
Sabur Naseer
10 ответов
+ 4
list() makes a list out of every character in a string or similar consecutive character occurence, even the spaces end up there. .split() literally splits a string or whatever into different pieces. it splits spaces if no parameter is given.
12th Jul 2020, 7:17 PM
Slick
Slick - avatar
+ 6
Another way a = "my string" b = [ *a ] #See tuple unpacking You can imagine strings as tuples of characters. The methods shared by Slick, Kiibo Ghayal and myself are equivalent in behavior. I think Slick's one is better because it's easier to read. Oma Falk Thanks. 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 What is separator? I don't know much of Python terminology.
12th Jul 2020, 7:25 PM
Kevin ★
+ 5
a = 'this is a string' b = list(a) print(b)
12th Jul 2020, 7:06 PM
Slick
Slick - avatar
+ 2
Thanks for the answer, it's working but can you please tell me how this worked? The way I know it, list should have only put the brackets around the string and define a list in code. How did it split the alphabets?
12th Jul 2020, 7:11 PM
Sabur Naseer
+ 2
Kevin ★ that's very nice
12th Jul 2020, 8:24 PM
Oma Falk
Oma Falk - avatar
+ 1
I see it now, thanks for explaining.
12th Jul 2020, 7:18 PM
Sabur Naseer
- 1
Hi
13th Jul 2020, 4:47 PM
Madisetty Manjula
Madisetty Manjula - avatar