[Solved] Convert a string representation of a set of tuples to a dictionary [duplicate]


Try using ast.literal_eval:

import ast
s="{(76034,0),(91316,0),(221981,768),(459889,0),(646088,0)}"
print(dict(ast.literal_eval('[' + s.strip('{}') + ']')))

Output:

{76034: 0, 91316: 0, 221981: 768, 459889: 0, 646088: 0}

solved Convert a string representation of a set of tuples to a dictionary [duplicate]