Parsing a string which represents a list of tuples

前端 未结 6 574
自闭症患者
自闭症患者 2021-01-01 20:15

I have strings which look like this one:

\"(8, 12.25), (13, 15), (16.75, 18.5)\"

and I would like to convert each of them into a python dat

6条回答
  •  忘掉有多难
    2021-01-01 20:54

    >>> import ast
    >>> print ast.literal_eval("(8, 12.25), (13, 15), (16.75, 18.5)")
    ((8, 12.25), (13, 15), (16.75, 18.5))
    

提交回复
热议问题