Skip to content
Advertisement

How to extract a list from a string in a list in python

I read a list of lists from a txt file and I got a list like this:

JavaScript

Each list item in this list is a str type which is a problem.

it should be like this:

JavaScript

How do I do that?

Advertisement

Answer

Using the eval() function along with a list comprehension we can try:

JavaScript

This prints:

JavaScript
Advertisement