Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Convert a string representation of list to list.



Convert a string representation of list to list...

Answer / Amit Kumar Gangele

In Python, you can convert a string representation of a list using the built-in `ast.parse` and `ast.literal_eval` functions. Here is an example: nn``pythonnimport astnnlist_str = '[1, 2, 3, 4]'nlist_obj = ast.literal_eval(ast.parse(list_str).body)[0]nnprint(list_obj) # Output: [1, 2, 3, 4]

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Why anaconda is used for python?

1 Answers  


Can you sort a string in python?

1 Answers  


Is python better than matlab?

1 Answers  


How is unit test done in python?

1 Answers  


What is tuple in python?

1 Answers  


In Python what is slicing?

1 Answers  


What is a class method?

1 Answers  


How are arguments passed by value or by reference in Python?

3 Answers  


Explain how to copy an object in Python.

1 Answers  


Where is python used?

1 Answers  


Is python a good first language?

1 Answers  


What is sphinx in python?

1 Answers  


Categories