1

I need to convert a string which has nested lists in it, into a list Is there a way to do this without the use of eval() and non standard python libraries? An example would be:

input = '[4,[5,6],7,[8,[9,10]],11,12,[13,14]]'
output = [4,[5,6],7,[8,[9,10]],11,12,[13,14]]

1 Answer 1

1

To convert the string

without the use of eval() and non standard python libraries

you could make use of json, which is part of the Python Standard Library:

import json

input_as_string = '[4,[5,6],7,[8,[9,10]],11,12,[13,14]]'
input_as_list = json.loads(input_as_string)

print(input_as_list.__class__)
#=> <class 'list'>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.