Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

How to Convert String to a List in Python

  • 02 Aug, 2025
  • Com 0
Python string to a list

In Python, to convert a string to a list of characters, use the list(string) method.

The easiest way to convert a string into a list of words (tokens) is by using string.split() method.

For basic filtering or transforming of strings into lists, apply list comprehension; use re.split() for advanced cases.

It depends on what your main objective is. It is helpful in parsing text, processing user input, and other NLP tasks.

Using list() constructor

Using list() constructor to convert a string into a list of characters in Python

The list() constructor splits a string into a list of individual characters. If the input string contains spaces and special characters, it becomes an element of a list too!

show = "Friends"

char_list = list(show)

print(char_list)

# Output: ['F', 'r', 'i', 'e', 'n', 'd', 's']

The above output shows that each character becomes a separate list element.

Empty string

Splitting an empty string in Python

No content in the string. Then, expect an empty list in the output.

empty_txt = ""

empty_list = list(empty_txt)

print(empty_list)

# Output: []

String with spaces and unicode characters

String with spaces and unicode characters

When the input string contains unicode characters, spaces, and emojis correctly, it will treat each as a single character and return a list without any error.

uni_txt = "héllo 😊"

uni_list = list(uni_txt)

print(uni_list)

# Output: ['h', 'é', 'l', 'l', 'o', ' ', '😊']

Using str.split()

Using str.split() method to convert a string into a list of words

Whether you want to split a string from a specific delimiter or transform it into a list of tokens(words), the str.split() method is your go-to place. It breaks a string into words.

netflix = "Eleven Tokyo Berlin Jonas"

character_list = netflix.split()  # Default delimiter: whitespace

print(character_list)

# Output: ['Eleven', 'Tokyo', 'Berlin', 'Jonas']

It splits a string using whitespace as a delimiter, which is the default setting. You can specify your own delimiter.

Custom delimiter

Converting a string to list based on custom delimiter in Python

Let’s say we have a string that contains a comma. We need to break a string at each comma.

netflix = "Eleven,Tokyo,Berlin,Jonas"

character_list = netflix.split(",")

print(character_list)

# Output: ['Eleven', 'Tokyo', 'Berlin', 'Jonas']

By passing “,” to the split() function, it splits a string at that point and returns a list containing all the splitted elements.

Multiple consecutive delimiters

Multiple consecutive delimiters

If delimiters appear back-to-back with nothing in between, empty elements will be included for each.

For example, if your string is “Eleven,,,Jonas”, that means two empty elements will be included in the output list.

netflix = "Eleven,,,Jonas"

character_between_empty = netflix.split(",")

print(character_between_empty)

# Output: ['Eleven', '', '', 'Jonas']

As expected, we got the list with four elements, of which two are empty.

If the delimiter is at the leading position and after that an element appears, the first element in the output list will be empty.

If the delimiter appears at the end of the string, the last element in the output will be empty.

Using list comprehension

Using list comprehension to convert a string into a list based on a condition

 

When you come across a string that contains alphanumeric characters, and you just want a list that contains alphabet characters individually, you should use a list comprehension. 

It provides splitting based on the condition while transforming into a list.

str = "kbl1921"

letters = [char for char in str if char.isalpha()]

print(letters)

# Output: ['k', 'b', 'l']

The output list only contains characters and filters out numeric values.

Using Regular Expressions (re.split())

Using Regular Expressions (re.split())

For complex string splitting, we can use the regular expression (re) module’s split() method because it provides a way to look for a pattern.

For example, suppose a string contains multiple different delimiters and you want to tackle it. In that case, you need to have a pattern that covers all the delimiters in one go and transform it into a proper list with correct elements.

import re

complex_input = "denver, ny;nj.washington"

# Split on comma, semicolon, or dot
clean_list = re.split("[,;\.]", complex_input)

print(clean_list)

# Output: ['denver', ' ny', 'nj', 'washington']

That’s all!

Post Views: 38
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

JavaScript Array push() Method
Pandas DataFrame head() Method

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend