Home > Enterprise >  Convert a string of list(tuple(int) into a proper list of tuple of int
Convert a string of list(tuple(int) into a proper list of tuple of int

Time:06-16

In a csv file Ive saved a list(tuple(int, int)) but when reading the line I get a string but how can I convert this "[(56, 365), (62, 801)]" to [(56, 365), (62, 801)]

CodePudding user response:

import ast

new_list = ast.literal_eval(your_list)

This should solve your problem!

CodePudding user response:

An easy but not very safe way would be to use eval(line) with line being the string to be parsed.

  • Related