Python Split String by Character: Into Characters or on a Delimiter

“Python split string by character” is asked about two completely different jobs, which is why the answers people find so often miss. One means breaking a string into its individual characters. The other means cutting it at a particular character:

list("a,b,c")        # ['a', ',', 'b', ',', 'c']   every character
"a,b,c".split(",")   # ['a', 'b', 'c']                cut at the commas

list() handles the first. str.split() handles the second. Both are covered below, along with the ValueError that comes from mixing them up.

The output shown under each block is from a run on Python 3.12.5.

Diagram comparing list() splitting a string into every character with split() cutting the same string at its delimiter characters
The same string, split two ways: every character, or cut at the commas.

The two meanings side by side

Run them together and the difference is obvious:

text = "a,b,c"

print("two different jobs, two different tools")
print()
print("1. into individual characters:")
print("   list(text)       ->", list(text))
print()
print("2. on a delimiter character:")
print("   text.split(',')  ->", text.split(","))
print()
print("same input, completely different answers")

Output:

two different jobs, two different tools

1. into individual characters:
   list(text)       -> ['a', ',', 'b', ',', 'c']

2. on a delimiter character:
   text.split(',')  -> ['a', 'b', 'c']

same input, completely different answers
Command Prompt comparing the Python list function and the split method on the same string
list() keeps the commas as items; split(",") consumes them.

Notice that split(",") throws the commas away. They were the cut marks, so they do not appear in the result.

Split a string into characters with list()

list() is the direct answer for turning a string into a list of characters:

word = "python"

characters = list(word)

print("word       ->", word)
print("list(word) ->", characters)
print("how many   ->", len(characters))
print()
print("each piece is itself a one character string:")
print("characters[0] ->", repr(characters[0]), type(characters[0]))
print()
print("and it goes back together with join:")
print('"".join(characters) ->', "".join(characters))

Output:

word       -> python
list(word) -> ['p', 'y', 't', 'h', 'o', 'n']
how many   -> 6

each piece is itself a one character string:
characters[0] -> 'p' <class 'str'>

and it goes back together with join:
"".join(characters) -> python

Python has no separate character type, so each item is a string of length one. That is why characters[0] reports str rather than something like char.

Joining them back is "".join(characters). If you need the pieces as a different type, converting a string to a list covers the variations.

Four ways to get a list of characters

There is more than one route, and they do not all cost the same:

import timeit

word = "hello"

print("list(word)        ->", list(word))
print("[c for c in word] ->", [c for c in word])
print("[*word]           ->", [*word])
print("tuple(word)       ->", tuple(word))
print("sorted(set(word)) ->", sorted(set(word)), " duplicates dropped")
print()

setup = "s = 'abcdefghij' * 500"
for label, snippet in [("list(s)        ", "list(s)"),
                       ("[*s]           ", "[*s]"),
                       ("[c for c in s] ", "[c for c in s]")]:
    secs = timeit.timeit(snippet, setup, number=20000)
    print(f"{label} {secs:.2f}s for 20,000 passes over 5,000 characters")

print()
print("list() and [*s] run in C; the comprehension loops in Python.")

Output:

list(word)        -> ['h', 'e', 'l', 'l', 'o']
[c for c in word] -> ['h', 'e', 'l', 'l', 'o']
[*word]           -> ['h', 'e', 'l', 'l', 'o']
tuple(word)       -> ('h', 'e', 'l', 'l', 'o')
sorted(set(word)) -> ['e', 'h', 'l', 'o']  duplicates dropped

list(s)         0.21s for 20,000 passes over 5,000 characters
[*s]            0.23s for 20,000 passes over 5,000 characters
[c for c in s]  0.90s for 20,000 passes over 5,000 characters

list() and [*s] run in C; the comprehension loops in Python.
Command Prompt showing four Python methods for splitting a string into characters with timing results
Four routes to the same list, timed over 20,000 passes.

list() and the unpacking form [*word] are several times quicker than the comprehension, because both run inside C rather than looping in Python. On short strings the gap is irrelevant, but it shows up on long text.

ExpressionGivesWhen to reach for it
list(s)list of charactersThe default. Clearest and fastest.
[*s]list of charactersHandy inside a larger expression.
[c for c in s]list of charactersOnly when you are also filtering or transforming.
tuple(s)tuple of charactersWhen the result must not change.
set(s)unique charactersDuplicate letters collapse into one.

The comprehension earns its place as soon as there is a condition attached, which is the next section.

Split a word into letters

Splitting a word into letters is the same call, with one caveat about what counts as a letter:

word = "Hello World 42!"

print("list(word) ->", list(word))
print()
print("it keeps the space, the digits and the punctuation too.")
print("for letters only, filter with isalpha:")
letters = [c for c in word if c.isalpha()]
print("letters    ->", letters)
print()
print("and to keep the letters but drop the case difference:")
print("lowercase  ->", [c.lower() for c in word if c.isalpha()])

Output:

list(word) -> ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', ' ', '4', '2', '!']

it keeps the space, the digits and the punctuation too.
for letters only, filter with isalpha:
letters    -> ['H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd']

and to keep the letters but drop the case difference:
lowercase  -> ['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']

list() is indiscriminate. Spaces, digits and punctuation all become items, so filtering with isalpha() is usually what people actually want.

For breaking a sentence into words instead of letters, use split a sentence into a list of words, and for digits specifically there is split a number into digits.

Split a string on a character

This is the delimiter reading of the question, and str.split() is the tool:

line = "name,age,city"

print('line.split(",")      ->', line.split(","))
print('maxsplit=1           ->', line.split(",", 1))
print('rsplit from the end  ->', "a,b,c".rsplit(",", 1))
print()
print("two results that surprise people:")
print('"abc".split(",")     ->', "abc".split(","), " no delimiter, so one piece")
print('"".split(",")        ->', "".split(","), "    an empty string, not an empty list")
print()
print("partition splits once and keeps the separator:")
print('"key=value=x".partition("=") ->', "key=value=x".partition("="))
print()
print("with no argument at all, split() uses runs of whitespace:")
print('"  a  b \t c \n".split() ->', "  a  b \t c \n".split())

Output:

line.split(",")      -> ['name', 'age', 'city']
maxsplit=1           -> ['name', 'age,city']
rsplit from the end  -> ['a,b', 'c']

two results that surprise people:
"abc".split(",")     -> ['abc']  no delimiter, so one piece
"".split(",")        -> ['']     an empty string, not an empty list

partition splits once and keeps the separator:
"key=value=x".partition("=") -> ('key', '=', 'value=x')

with no argument at all, split() uses runs of whitespace:
"  a  b 	 c 
".split() -> ['a', 'b', 'c']
Command Prompt showing Python split on a delimiter character with maxsplit rsplit and partition
split() with a delimiter, plus maxsplit, rsplit() and partition().

Two results catch people out. Splitting a string that does not contain the delimiter gives a one-item list rather than an error, and splitting an empty string gives [''] rather than an empty list.

That second one matters when you are checking results with if not pieces, because a list holding one empty string is still truthy. Comma separated input has its own guide in split a string by comma, and splitting on spaces covers the whitespace case.

Why split(“”) raises ValueError

The obvious guess for splitting into characters does not work:

text = "hello"

try:
    text.split("")
except ValueError as err:
    print('text.split("") -> ValueError:', err)

print()
print("split() needs something to split ON, and an empty string is nothing.")
print("when you want every character, that is list():")
print("list(text) ->", list(text))

Output:

text.split("") -> ValueError: empty separator

split() needs something to split ON, and an empty string is nothing.
when you want every character, that is list():
list(text) -> ['h', 'e', 'l', 'l', 'o']
Command Prompt showing the Python ValueError empty separator raised by calling split with an empty string
split("") raises ValueError: empty separator.

The message is exact. split() looks for a separator inside the string, and an empty string is found everywhere and nowhere, so Python refuses rather than guessing. list() is the call you wanted.

Splitting on several different characters

str.split() takes one delimiter. For several, re.split() takes a pattern:

import re

messy = "apple,banana;cherry date|elderberry"

print("one delimiter is not enough here, so use re.split:")
print(re.split(r"[,;| ]", messy))
print()
print("a + collapses runs of them, which avoids empty strings:")
print(re.split(r"[,;| ]+", "apple,,banana;;cherry"))
print()
print("compare the plain version, which leaves gaps:")
print(re.split(r"[,;| ]", "apple,,banana;;cherry"))
print()
print("wrapping the pattern in a group keeps the separators:")
print(re.split(r"([,;])", "a,b;c"))
print()
print("and re.findall with a dot is another route to single characters:")
print(re.findall(r".", "hey"))

Output:

one delimiter is not enough here, so use re.split:
['apple', 'banana', 'cherry', 'date', 'elderberry']

a + collapses runs of them, which avoids empty strings:
['apple', 'banana', 'cherry']

compare the plain version, which leaves gaps:
['apple', '', 'banana', '', 'cherry']

wrapping the pattern in a group keeps the separators:
['a', ',', 'b', ';', 'c']

and re.findall with a dot is another route to single characters:
['h', 'e', 'y']

The + is worth adding. Without it, two delimiters in a row produce an empty string between them, which then has to be filtered out afterwards.

Wrapping the pattern in a group keeps the separators in the output, which is useful when you plan to reassemble the string later. There is more on patterns in splitting strings with regex and multiple delimiters.

You often do not need a list at all

Strings are iterable already, so building a list first is frequently wasted work:

word = "python"

print("a string is already iterable, so a list is often unnecessary:")
for character in word:
    print("  ", character, end="")
print()
print()

print("counting vowels, no list built:")
print("  ", sum(1 for c in word if c in "aeiou"))

print("upper case each one:")
print("  ", [c.upper() for c in word])

print("with positions:")
print("  ", list(enumerate(word))[:3], "...")

print()
print("calling list() first only wastes memory when you just want to loop.")

Output:

a string is already iterable, so a list is often unnecessary:
   p   y   t   h   o   n

counting vowels, no list built:
   1
upper case each one:
   ['P', 'Y', 'T', 'H', 'O', 'N']
with positions:
   [(0, 'p'), (1, 'y'), (2, 't')] ...

calling list() first only wastes memory when you just want to loop.

Looping straight over the string reads better and allocates nothing. Reach for list() when you genuinely need indexing, slicing or a result you can mutate.

Accented letters and emoji do not split cleanly

This is where character splitting stops being simple:

import unicodedata

# printed with ascii() so the console encoding cannot mangle the output
decomposed = "cafe" + "\u0301"          # 'e' followed by a combining acute accent

print("the word looks like 5 letters but is stored as:")
print("  len          ->", len(decomposed))
print("  list()       ->", ascii(list(decomposed)))
print("  the accent came off the e and became its own item")
print()

composed = unicodedata.normalize("NFC", decomposed)
print("after unicodedata.normalize('NFC', ...):")
print("  len          ->", len(composed))
print("  list()       ->", ascii(list(composed)))
print()

family = "\U0001F468\u200D\U0001F469\u200D\U0001F467"   # one family emoji
print("a single family emoji:")
print("  len          ->", len(family))
print("  list() gives ->", len(family), "separate pieces, none of which display correctly")
print()
print("bytes are not characters either:")
print("  'naive' with an umlaut, encoded ->", ascii(("na" + "\u00ef" + "ve").encode("utf-8")))
print("  that is", len(("na" + "\u00ef" + "ve").encode("utf-8")), "bytes for", len("na" + "\u00ef" + "ve"), "characters")

Output:

the word looks like 5 letters but is stored as:
  len          -> 5
  list()       -> ['c', 'a', 'f', 'e', '\u0301']
  the accent came off the e and became its own item

after unicodedata.normalize('NFC', ...):
  len          -> 4
  list()       -> ['c', 'a', 'f', '\xe9']

a single family emoji:
  len          -> 5
  list() gives -> 5 separate pieces, none of which display correctly

bytes are not characters either:
  'naive' with an umlaut, encoded -> b'na\xc3\xafve'
  that is 6 bytes for 5 characters
Command Prompt showing how Python list splits a combining accent off its letter and breaks an emoji into pieces
A combining accent and an emoji both come apart under list().

An accented letter can be stored two ways: as one character, or as a plain letter followed by a combining mark. In the second form list() separates the accent from its letter, and the pieces no longer display properly.

Running unicodedata.normalize("NFC", text) first merges them back into single characters, which makes the split behave the way you expect.

Emoji built from several code points, such as family emoji or flags, cannot be fixed this way. If your text contains them, split on grapheme clusters with a library rather than on characters.

Which one do you need?

What you wantUseResult for "a,b,c"
Every characterlist(s)['a', ',', 'b', ',', 'c']
Cut at one characters.split(",")['a', 'b', 'c']
Cut at several charactersre.split(r"[,;]", s)['a', 'b', 'c']
Cut once onlys.split(",", 1)['a', 'b,c']
Letters only[c for c in s if c.isalpha()]['a', 'b', 'c']
Fixed size chunkssplit every nth character['a,', 'b,', 'c']

A few more string guides that pair well with this one:

Frequently asked questions

How do I split a string into characters in Python?

Call list(text). It returns a list holding every character as a one-character string, so list("abc") gives ['a', 'b', 'c'].

Why does split(“”) give a ValueError?

str.split() needs a separator to look for, and an empty string is not one, so Python raises ValueError: empty separator. Use list() when you want every character.

What is the difference between list() and split() on a string?

list() keeps every character, delimiters included. split(sep) cuts the string at each sep and throws the separators away.

How do I split a word into letters in Python?

list(word) gives every character. Add a filter, [c for c in word if c.isalpha()], if you want to exclude spaces, digits and punctuation.

How do I convert a string to a list of characters?

list(s) or [*s]. Both build the same list, and both are faster than a list comprehension because they run in C rather than looping in Python.

How do I split a string on more than one character?

Use re.split(r"[,;|]+", text). The square brackets list the characters to cut at and the + stops empty strings appearing between consecutive delimiters.

Why does splitting an emoji or accented letter go wrong?

Those can occupy several code points, and list() works one code point at a time. Normalising with unicodedata.normalize("NFC", text) fixes accents; the rules are set out in the Python str.split documentation and the unicodedata module.