>>> import ast
>>> x = '[ "A","B","C" , " D"]'
>>> x = ast.literal_eval(x)
>>> x
['A', 'B', 'C', ' D']
>>> x = [n.strip() for n in x]
>>> x
['A', 'B', 'C', 'D']

ast.literal_eval:

Evaluate an expression node or a string containing only a Python literal or container display. The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, None and Ellipsis.

This can be used for evaluating strings containing Python values without the need to parse the values oneself. It is not capable of evaluating arbitrarily complex expressions, for example involving operators or indexing.

Answer from Roger Pate on Stack Overflow
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ how to convert a list to string in python easily [2026]
How to Convert a List to String in Python Easily [2026]
December 1, 2025 - Learn simple methods to convert a Python list to a string with step-by-step examples and code snippets. Master Python string conversion quickly and easily.
๐ŸŒ
StrataScratch
stratascratch.com โ€บ blog โ€บ python-list-manipulation-convert-lists-to-strings
Python List Manipulation: Convert Lists to Strings - StrataScratch
April 4, 2025 - To handle this, use repr() to represent each item exactly as Python sees it. It escapes characters and makes things easier to debug or store. In the code below, a list is filled with special characters: newline, tab, and quotes. The repr(item) for item in specials part turns each item into its string representation, showing escaped characters like \n and \t.
Discussions

python - How to convert list to string - Stack Overflow
How can I convert a list to a string using Python? ... str(anything) will convert any python object into its string representation. Similar to the output you get if you do print(anything), but as a string. ... So one way to make this different than that one is to suggest using json to do it like ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
converting a string that is list-like into a list
ast.literal_eval should get pretty close, though it would probably give you an earful on the a and b. Otherwise it would seem like the ideal solution. eval works, but I'd never use it with direct user input no matter where it came from. And even then it would need a and b defined, at least. If you really can't do anything about the input, then a custom parser like yours seems like the only way forward. Technically speaking regular expressions could probably be used, but I don't really like using them unless I have to or they're perfect for the job. More on reddit.com
๐ŸŒ r/learnpython
30
1
July 11, 2022
what is the difference between list and list[str]?
From your list with parts of the verse, loop through and build your output str by concatenating to an empty string with + (up to the thing before the last part). The last part concatenate with an and. More on reddit.com
๐ŸŒ r/learnpython
4
1
August 21, 2021
Strings are lists?
Strings are not lists. Strings are strings. In the background strings use an array (not a list) of characters (8-bit unsigned integers) to store data. However, strings respond to the same indexing commands that a list does, and that includes the reverse indexing: reversed_string = original_string[::-1] More on reddit.com
๐ŸŒ r/learnpython
17
2
July 6, 2018
People also ask

What are the different methods to convert a list to a string in Python?
There are several methods to achieve this, including using the join() method, using a loop with string concatenation, using list comprehension, and using the str() function.
๐ŸŒ
simplilearn.com
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ how to convert a list to string in python easily [2026]
How to Convert a List to String in Python Easily [2026]
Are there any other Python built-in functions to convert lists to strings?
Besides the join() method, you can also directly use the str() function to convert a list to a string. However, the str() function will include the brackets and commas, making it less suitable for a readable representation.
๐ŸŒ
simplilearn.com
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ how to convert a list to string in python easily [2026]
How to Convert a List to String in Python Easily [2026]
Why would I need to convert a list to a string in Python?
Converting a list to a string is useful when you want to display the elements of the list as a single, human-readable string or when you need to write the list data to a file or a database in a specific format.
๐ŸŒ
simplilearn.com
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ how to convert a list to string in python easily [2026]
How to Convert a List to String in Python Easily [2026]
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ how-to-convert-a-list-to-a-string-in-python
How to Convert a List to a String in Python | DataCamp
April 12, 2024 - When converting lists to strings in Python, it's easy to encounter a few common pitfalls. Here's a rundown of some typical issues you might face, along with tips on how to avoid them: Lists Containing Different Data Types: All elements must be strings when using methods like .join().
๐ŸŒ
Google
developers.google.com โ€บ google for education โ€บ python โ€บ python lists
Python Lists | Python Education | Google for Developers
List literals are written within square brackets [ ]. Lists work similarly to strings -- use the len() function and square brackets [ ] to access data, with the first element at index 0.
Find elsewhere
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-list-to-string-how-to-convert-lists-in-python
Python List to String โ€“ How to Convert Lists in Python
July 7, 2023 - By using the map() function with the str() function, you can easily convert each element of a list to a string and then combine them into a single string. This method is particularly useful when you have a large list and want a concise way to ...
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-convert-string-to-list
How To Convert a String to a List in Python | DigitalOcean
April 9, 2026 - Yes, you can convert a string to a list using methods like split(), list comprehension, or json.loads().
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-convert-a-list-to-string
Python Program to Convert a List to String - GeeksforGeeks
May 8, 2026 - Another approach is to use a loop (for loop) to iterate through the list and concatenate each element to a result string. This method provides more control if we need to manipulate each element before adding it to the string. ... a = ["Python", "is", "simple"] res = "" # Convert list to string using a loop for x in a: res += x + " " print(res.strip()) # Remove trailing space
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ list-to-string-python
Convert List to String in Python: 7 Best Methods (with code)
June 8, 2023 - Learn different methods for how to convert a list to a string in Python with examples. This includes list comprehension, join, and map functions.
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ convert-string-to-list-in-python
Convert String to List in Python - Flexiple - Flexiple
The ast.literal_eval() method, found in the ast module (Abstract Syntax Trees), is designed to parse strings containing Python literals and safely evaluate them. This method is particularly useful for converting strings that look like Python ...
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to convert a list to a string in python
How to convert a list to a string in Python | Replit
February 5, 2026 - Iterable: The method takes an iterable, like the fruits list, as its argument. It efficiently combines the list elements into one string, placing the separator between each element. This approach is generally better than using a loop with the + operator because it's faster and more memory-friendly, especially for large lists. For more details on using join() in Python...
๐ŸŒ
OneUptime
oneuptime.com โ€บ home โ€บ blog โ€บ how to convert list to string in python
How to Convert List to String in Python
January 25, 2026 - words = ['Hello', 'World', 'from', ... no separator combined = ''.join(words) print(combined) # 'HelloWorldfromPython' The join() method only works with iterables whose elements are strings. numbers = [1, 2, 3, 4, 5] # This ...
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ convert-list-to-string-python
Convert list to string in Python - 3 easy ways - Flexiple Tutorial - Flexiple
March 10, 2022 - And in our case, we use it to convert each value in the list into a string. ... By using the str() function which converts objects to a string we can convert the int values into a string before using the join method. Code to convert python list to string using map():
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ converting a string that is list-like into a list
r/learnpython on Reddit: converting a string that is list-like into a list
July 11, 2022 -

Hopefully I can explain this properly. I have no control over how the input string which is kind of formatted like a list of lists but without quotes (so I can't use json.loads)

Example input (I'm reading it in using sys.argv):

"[[a,1],[b,2]]"

I'd like to convert this to be a real list of lists so I can iterate through them in my script.

I can get what I need using split but I was wondering if there was a better way to do it. Either a better way to divide them or a way to add quotes - whatever works.

import sys

try1 = sys.argv[1]
lst1 = try1.split("],")
print("try #1 (works but could be better?)")
print(len(lst1))
for item in lst1:
    print(item.lstrip("[[").rstrip("]]"))

# doesn't work - 1 item in the list
print("\n\nTry #2")
try2 = sys.argv[1:]
print(len(try2))

# doesn't work - length of 13
print("\n\nTry #3")
print(len(list(sys.argv[1])))

Output

$ python3 t.py "[[a,1],[b,2]]"
try #1 (works but could be better?)
2
a,1
b,2


Try #2
1


Try #3
13

Thanks for reading

๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ string-list-python
https://www.dotnetperls.com/string-list-python
This program creates 2 equivalent string lists. It then performs some simple operations on the lists, such as getting the length and looping. Part 1 The list initializer syntax is used.
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ 5 ways to convert string to a list in python
5 Ways to Convert String to a List in Python - Analytics Vidhya
April 22, 2025 - One popular method for converting a string to a list in Python is using the list() constructor. This constructor takes an iterable, such as a string, and converts it into a list by considering each character as a separate element.
๐ŸŒ
Pluralsight
pluralsight.com โ€บ blog โ€บ software development
6 Best Methods for Python String to List Conversion | Pluralsight
Learn the 6 best Python methods for converting strings to lists, such as using list(), split(), list comprehension, and more for Python string manipulation.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ convert string to list in python
Convert String to List in Python - AskPython
January 16, 2024 - Here, we are going to see how we can combine both the above methods to convert a string to a list of character lists. ... #Given string string1="This is Python" print("The actual string:",string1) #converting string1 into a list of strings string1=string1.split() #applying list method to the individual elements of the list string1 list1=list(map(list,string1)) #printing the resultant list of lists print("Converted to list of character list :\n",list1)
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ turn-a-list-into-a-string
Convert a list to a string in Python - Python Morsels
December 6, 2021 - Want to turn a list of strings into a single string? You can use the string join method to join a list of strings together (concatenating them with a delimiter of your choice). Trey Hunner Dec. 6, 2021 3 min read 03:04 video Python 3.10โ€”3.14