import ast
y = ast.literal_eval(input)
[x[0] for x in y]
感谢@stephan为我指出了正确的方向ast.literal_评估. 文件描述如下:
Safely evaluate an expression node or
a string containing a Python
expression. The string or node
provided may only consist of the
following Python literal structures:
strings, numbers, tuples, lists,
dicts, booleans, and None.
This can be used for safely evaluating
strings containing Python expressions
from untrusted sources without the
need to parse the values oneself.
感谢@stephan为我指出了正确的方向ast.literal_评估. 文件描述如下:
注意:这是Python2.6中的新功能。在
希望我能理解。在
相关问题 更多 >
编程相关推荐