'python how to concert a string word to a list of letters [duplicate]
I have a word:
'shrewd'
How can I convert it into:
['s','h','r','e','w','d']
I have tried:
delim = ','
x = 'shrewd'.split(delim)
x
But not working ,any friend can help ?
Solution 1:[1]
There aren't any commas in your string, so you won't be able to get your desired output using .split().
Since strings are iterable, you can use:
data = 'shrewd'
print(list(data))
This outputs:
['s', 'h', 'r', 'e', 'w', 'd']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BrokenBenchmark |
