Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsThe right way to convert a string to a Python list without split() depends on what the string represents. Use list(text) when you want one list item per character; use ast.literal_eval() for text written as a Python list literal, or json.loads() for JSON. These methods produce different results, so choose based on the input’s format and intended items.
Make a list of characters
A Python string is a sequence of characters. Passing it to list(), or iterating over it in a comprehension, creates one element for each character—including spaces and punctuation.
text = "red blue"
items = list(text)
# ['r', 'e', 'd', ' ', 'b', 'l', 'u', 'e']
items = [character for character in text]
# ['r', 'e', 'd', ' ', 'b', 'l', 'u', 'e']
Use a comprehension when you also need to transform or filter characters. For example, this keeps characters that str.isalpha() considers alphabetic:
text = "a1b2"
letters = [character for character in text if character.isalpha()]
# ['a', 'b']
This is character filtering, not word splitting. It can discard punctuation or spacing that matters to your data.
#1 Best Overall
Convert text containing a Python list literal
If the string contains Python literal syntax, such as "['red', 'blue']", parse that representation with ast.literal_eval() rather than turning the string’s characters into a list.
import ast
text = "['red', 'blue']"
items = ast.literal_eval(text)
# ['red', 'blue']
ast.literal_eval() handles Python literals and containers, including lists, strings, numbers, dictionaries, tuples, sets, booleans, None, and Ellipsis. It does not evaluate arbitrary expressions, operators, or indexing. A valid input may therefore produce a value that is not a list; check the result’s type if the rest of your program requires a list. Malformed input can raise an exception. See the Python documentation for ast.literal_eval().
Rank #2
Unlike eval(), this function does not execute general Python code or perform name lookups. That does not make it suitable for every untrusted input: Python’s documentation warns that hostile or unusually complex data can consume excessive memory, stack, or CPU, and does not recommend calling it on untrusted data. For adversarial input, use a defined serialization format and suitable size and complexity limits.
Convert a JSON array string
When the text comes from a JSON source, use the JSON decoder. A valid JSON array becomes a Python list:
import json
text = '["red", "blue"]'
items = json.loads(text)
# ['red', 'blue']
JSON and Python literal syntax are different formats, even when simple examples look similar. Match the decoder to the format used by the producer; invalid JSON raises a decoding error. See the Python JSON documentation.
What if you want words or delimiter-separated fields?
If the intended items are words or fields, identify the delimiter and the input grammar before writing a parser. A character-by-character loop can implement custom parsing, but delimiters inside quotes, escaped delimiters, nested values, and empty fields can make an ad hoc parser error-prone. For structured data, use its standard decoder, such as json.loads() for JSON, or a parser designed for the specific format. Stripping brackets and punctuation is not a general way to recover list items.
Quick decision guide
| What the string represents | Use | What you get |
|---|---|---|
| Characters in ordinary text | list(text) or a comprehension over text |
One element per character, including whitespace and punctuation |
| A Python literal representation | ast.literal_eval(text) |
The represented Python literal; check that its type is the list your code expects |
| A JSON array | json.loads(text) |
A Python list for a valid JSON array |
| Words or custom-delimited fields | A parser matching the delimiter and grammar | Depends on the format; account for quoting, escapes, and empty fields |
Common mistake: expecting words from list()
list("cat") returns ['c', 'a', 't'], not ['cat']. Likewise, putting text that looks like a list inside a string does not create a list automatically. If the string represents serialized items, parse it according to its actual format.
Quick Recap
Best Value
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.
Recommended Free Tools




