Python Practice › List Programs › Program 37
Convert a string to a list
Write a Python program to convert a string into a list of words and a list of characters.
Input
"learn python"
Output
['learn', 'python'] ['l', 'e', 'a', 'r', 'n', ' ', 'p', 'y', 't', 'h', 'o', 'n']
Approach
split()for words,list()for characters.
Solution
text = "learn python"print(text.split())print(list(text))Output
['learn', 'python'] ['l', 'e', 'a', 'r', 'n', ' ', 'p', 'y', 't', 'h', 'o', 'n']
Learn the concept
New to this topic? Read the lesson, then come back.