Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

Convert a String to a List in Python

Use list(text) for individual Python string elements, or choose split(), splitlines(), or re.split() when words, fields, lines, or pattern-based segments are the intended items.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use list(text) when you want one Python string element for each element of a string. If you mean words, comma-separated fields, lines, or segments defined by a pattern, use the corresponding split operation instead: the right conversion depends on what should count as one item.

Convert a string into individual elements

In Python, the usual sequence type meant by “array” in this task is a list. Pass the string to list():

text = "hello"
letters = list(text)
print(letters)  # ['h', 'e', 'l', 'l', 'o']

Python defines strings as immutable sequences of Unicode code points; indexing a string produces a string of length one. Accordingly, list(text) returns a list of one-code-point strings, not necessarily one item per user-perceived character. For example, a base letter followed by a combining accent can comprise more than one code point. See the Python 3.14.8 built-in types documentation for string semantics.

Choose the operation for the boundary you want

Split into whitespace-separated words

Call split() without an argument:

text = "  red   green blue  "
words = text.split()
# ['red', 'green', 'blue']

Whitespace runs act as a single separator, and leading or trailing whitespace is omitted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Split on a fixed delimiter

Pass the delimiter to split() when the string uses a known separator, such as a comma:

text = "red,green,blue"
fields = text.split(",")
# ['red', 'green', 'blue']

Unlike whitespace mode, explicit-separator splitting preserves empty fields between adjacent separators. An empty string also produces an empty field when split on an explicit separator:

"1,,2".split(",")  # ['1', '', '2']
"".split(",")       # ['']

This distinction matters when empty values carry meaning in the data you are parsing.

Split into lines

Use splitlines() to turn line-separated text into a list:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
text = "firstnsecondn"
lines = text.splitlines()
# ['first', 'second']

Line boundaries are omitted by default. An empty string produces [], and a final line break does not add an extra empty item.

Split using a pattern

For multiple or pattern-based separators, use re.split() from the standard-library re module:

import re

text = "red, green; blue"
parts = re.split(r"[,;]s*", text)
# ['red', 'green', 'blue']

For one fixed delimiter, str.split() is simpler. The Python documentation covers the built-in string splitting methods at docs.python.org.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Quick choice guide

What each list item should represent Use What to expect
Individual Python string elements list(text) One string per Unicode code point
Whitespace-separated words text.split() Whitespace runs collapse; surrounding whitespace is omitted
Fields separated by one known delimiter text.split(",") Adjacent separators preserve empty fields
Lines text.splitlines() Line boundaries are omitted by default
Segments separated by a pattern re.split(pattern, text) Use a regular expression for multiple or pattern-based separators

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

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

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.