Python Practice › List Programs › Program 37

Convert a string to a list

EasyList Programs · 37 of 100

Write a Python program to convert a string into a list of words and a list of characters.

Advertisement
Input
"learn python"
Output
['learn', 'python']
['l', 'e', 'a', 'r', 'n', ' ', 'p', 'y', 't', 'h', 'o', 'n']

Approach

  1. split() for words, list() for characters.

Solution

Python
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.

More list programs

← All 100 List Programs

Leave a Comment