input : a string = "[('0.0.0.0',5656), ('0.0.0.0',5656), ('0.0.0.0',5656), ('0.0.0.0',5656)]"
desired output: a tuple list [('0.0.0.0',5656), ('0.0.0.0',5656), ('0.0.0.0',5656), ('0.0.0.0',5656)]
CodePudding user response:
As mentioned by @Shinratensei, you can use ast
import ast
output = ast.literal_eval("[('0.0.0.0',5656), ('0.0.0.0',5656), ('0.0.0.0',5656), ('0.0.0.0',5656)]")
# [('0.0.0.0', 5656), ('0.0.0.0', 5656), ('0.0.0.0', 5656), ('0.0.0.0', 5656)]