Use the ast module

>>> import ast
>>> list_as_string = "['item 1', 'item 2', 'item 3']"
>>> _list = ast.literal_eval(list_as_string)
>>> _list
['item 1', 'item 2', 'item 3']
>>>
Answer from C.B. on Stack Overflow
๐ŸŒ
Python Guides
pythonguides.com โ€บ convert-string-to-list-in-python-without-using-split
Convert String to List in Python Without Using Split
May 16, 2025 - The simplest way to convert a string to a list without using split() is to use the Python built-in list() function.
Discussions

python - string to list and list to string conversion - without split - Stack Overflow
Could you share how to convert string to list and vice versa as shown below (without splitting each words) Input: string 'I am a boy' Output: ['I am a boy'] and Input: list ['I am a boy'] Output: More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Convert string (without any separator) to list - Stack Overflow
I have a phone number(string), e.g. "+123-456-7890", that I want to turn into a list that looks like: [+, 1, 2, 3, -, ...., 0]. Why? So I can go iterate through the list and remove all the symbol... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to convert string to list (NOT list(str), it is how to make list(' "a", 1, 3 )') work)
API? Parse the response as JSON. More on reddit.com
๐ŸŒ r/learnpython
5
3
May 24, 2022
Python: How to convert string to list without creating over-arching list - Stack Overflow
I've been sent data in a horrible format, consisitng of a series of points with subsequent attributes. Each point is bounded by square brackets [] but is currently a string type. I've tried the st... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ split string to list without split method
r/learnpython on Reddit: Split string to list without split method
December 25, 2021 - This means if you change a character in your Python-string, you only change a character inside your char[], but in order to get a list you need to allocate memory for such a list, split the string into different Python objects, etc.
๐ŸŒ
Quora
quora.com โ€บ How-do-I-convert-a-string-to-a-list-without-splitting-in-Python
How to convert a string to a list without splitting in Python - Quora
Answer (1 of 2): Your homework is answered! [code]def string_parts(s, n=" "): t = "" l = [] for i in s: if i == n: l.append(t) t = "" else: t += i if t: l.append(t) return l in_string = "For ยฃ10 pounds you can get $20, in my dreams!" l_string = string_parts(in_string) pri...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-program-convert-string-list
Convert string to a list in Python - GeeksforGeeks
Explanation: [ch for ch in s] with this list comprehension we iterate over each character (ch) in the string "s" and add it to the list. ... Python provides built-in type conversion functions to easily transform one data type into another. This article explores the process of converting objects into strings which is a basic aspect of Python programming.Since every element in Python is an object, we can use the built-in str() and repr() m
Published: May 5, 2025
Find elsewhere
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-convert-string-to-list
How To Convert a String to a List in Python | DigitalOcean
Convert strings to lists in Python using split(), list(), json.loads(), and more. Complete guide with examples for various string formats and use cases.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to convert string to list (not list(str), it is how to make list(' "a", 1, 3 )') work)
r/learnpython on Reddit: How to convert string to list (NOT list(str), it is how to make list(' "a", 1, 3 )') work)
May 24, 2022 -

Given I have the following string

a = '["b", "s", 1]'

How would I convert it to an actual list? (If I do print(type(a)) it will say <class 'str'>, but I want to print <class 'list'> )

One way would be to use a for loop with string.split(',') along with a small bit of processing to remove the brackets and stuff. but I have some reasons (more like assumptions) for not doing so:

  1. I might be working on a LONG list per user which is already pretty slow, and maybe, just maybe, if I get alot of requests from my API it might really slow down the processing. (I have to remove duplicates too after this, I can't do OrderedSet(list) because it won't keep the insertion order.)

  2. I am going to be hosting this on Heroku (its a flask API and well this might FURTHER slow down the processing).

The above reasons are really my assumptions, not really researched reasons (so they might be incorrect)

So what is an efficient, fast way to do this on a flask server (even if the list is long)? Could somehow numpy arrays help me? ( it will be between 250-500 items)

๐ŸŒ
Pluralsight
pluralsight.com โ€บ blog โ€บ software development
6 Best Methods for Python String to List Conversion | Pluralsight
We have set the delimiter as โ€˜-โ€™, so the string is split accordingly. String slicing is a popular method to extract substrings from a string. Combining it with list comprehension can convert a string to a list.
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ string โ€บ convert-string-to-list-in-python
Convert String to List in Python - AskPython
January 16, 2024 - What if we need a list of characters present in a string? In that case, direct type conversion from string to list in Python using the list() method does the
Top answer
1 of 1
4

If the string looks like a syntactically valid Python list, then you can get that list data by calling ast.literal_eval:

>>> import ast
>>> s = "[[451166.32,719761.36,20.37,0.06,],[451162.97,719765.06,20.41,0.048,1],[451161.63,719766.54,10.17,0.048,],[451158.26,719770.23,20.44,0.048,],[451156.19,719772.54,20.05,0.048,0],[451148.7,719780.68,-10.77,0.048,],[451138.57,719791.95,-10.2,0.048,],[451129.33,719802.15,-10.38,0.048,],[451118.07,719814.56,10.06,0.048,],[451105.98,719827.91,-10.64,0.048,],[451095.10,719839.91,-10.47,0.048,],[451087.17,719848.66,-10.72,0.048,],[451082.94,719853.31,10.92,0.048,0],[451078.,719858.77,2.75,10.048,],[451076.79,719860.10,5.2,10.06,1]]"
>>> x = ast.literal_eval(s)
>>> type(x)
<class 'list'>
>>> x
[[451166.32, 719761.36, 20.37, 0.06], [451162.97, 719765.06, 20.41, 0.048, 1], [451161.63, 719766.54, 10.17, 0.048], [451158.26, 719770.23, 20.44, 0.048], [451156.19, 719772.54, 20.05, 0.048, 0], [451148.7, 719780.68, -10.77, 0.048], [451138.57, 719791.95, -10.2, 0.048], [451129.33, 719802.15, -10.38, 0.048], [451118.07, 719814.56, 10.06, 0.048], [451105.98, 719827.91, -10.64, 0.048], [451095.1, 719839.91, -10.47, 0.048], [451087.17, 719848.66, -10.72, 0.048], [451082.94, 719853.31, 10.92, 0.048, 0], [451078.0, 719858.77, 2.75, 10.048], [451076.79, 719860.1, 5.2, 10.06, 1]]

I'm not completely sure, but it sounds like your string might actually look like multiple lists concatenated together, in which case you can't just call literal_eval on it:

>>> import ast
>>> s = "[1,2][3,4,[[5,6],7]][8,9]"
>>> ast.literal_eval(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Programming\Python 3.6\lib\ast.py", line 85, in literal_eval
    return _convert(node_or_string)
  File "C:\Programming\Python 3.6\lib\ast.py", line 84, in _convert
    raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.Subscript object at 0x02E25650>

If this is the case, you can separate your data into individual groups so you can eval them independently.

import ast

def separate_groups(s):
    """finds matching square brackets within `s` and yields successive portions that resemble valid list literals.
    note: may not operate correctly on data that contains quoted brackets, for example `"[1, '[', 2][3,4]"`
    """
    depth = 0
    last_seen_group_end = -1
    for i,c in enumerate(s):
        if c == "[":
            depth += 1
        elif c == "]":
            depth -= 1
            if depth == 0:
                yield s[last_seen_group_end+1: i+1]
                last_seen_group_end = i

s = "[1,2][3,4,[[5,6],7]][8,9]"
result = [ast.literal_eval(group) for group in separate_groups(s)]
print(result)

Result:

[[1, 2], [3, 4, [[5, 6], 7]], [8, 9]]
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-convert-a-list-to-string
Python Program to Convert a List to String - GeeksforGeeks
May 8, 2026 - The join() method is one of the most common and efficient ways to convert a list of strings into a single string. This method is ideal for lists that contain only string elements.
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-string-to-list
How to Convert String to List in Python?
April 3, 2025 - If a string represents a nested JSON structure, a simple .split() wonโ€™t work. Instead, Python json.loads() can parse it into a dictionary.
๐ŸŒ
IONOS
ionos.com โ€บ digital guide โ€บ websites โ€บ web development โ€บ converting python strings to lists
How to convert strings to lists in Python - IONOS
December 12, 2024 - If no separator is provided, the method defaults to splitting the string at blank spaces. maxsplit (optional): maxsplit defines the maximum number of splits to be made. If you want Python to carry out all possible splits, you can either set the parameter to -1 or leave it blank.
๐ŸŒ
BlueVPS
bluevps.com โ€บ blog โ€บ how to convert a string to a list in python: step-by-step guide
How to Convert a String to a List in Python: Step-by-Step Guide - Blog - BlueVPS
August 26, 2025 - This guide will walk through various methods of how to convert string to list in Python, explain their use cases, and highlight potential performance considerations. By the end, youโ€™ll be able to confidently choose the right approach for your project. Before diving into the techniques, itโ€™s worth asking: why bother converting? Data preprocessing โ€“ text often needs to be split into words or tokens.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ python โ€“ convert string to list
Python - Convert String to List - AskPython
June 21, 2021 - Pythonโ€™s ast (Abstract Syntax Tree) module is a handy tool that can be used to deal with strings like this, dealing with the contents of the given string accordingly. We can use ast.literal_eval() to evaluate the literal and convert it into a list.
๐ŸŒ
codippa
codippa.com โ€บ home โ€บ how to convert string to list of characters in python
How to convert string to list of characters in python - codippa
January 3, 2024 - Python list comprehension can be used to convert string to list of characters as shown below. str = 'codippa' l = [c for c in str] print('List is:',l) ... To convert a string to list of characters, we can also use list slicing as shown below.