-1

How can I convert a arbitrarily nested list of literals (string/numbers) to its string representation? For example,

nested_list = [[1,2,4],[1, [1, 2], [1]],2]
nested_list_string = "[[1,2,4],[1, [1, 2], [1]],2]"

Furthermore , it could be multilines:

[
    1, 2,
    [2,4]
]

can produces the string representation of equivalent single-line list i.e "[1,2, [2,4]]" or any other equivalent form.

DurgaDatta
  • 3,952
  • 4
  • 27
  • 34

1 Answers1

1

Do this with str.

str(nested_list)
Bill
  • 453
  • 3
  • 9