I have an input file with the following format:
[(1,1),(2,1)], 'add', 11
[(1,2),(1,3)], 'div', 2
[(3,1),(4,1),(3,2),(4,2)], 'times', 240
[(2,2),(2,3)], 'minus', 3
...
Each line is a tuple I want to create. How is it possible to convert each string line into a tuple?
For example, line string "[(1,1),(2,1)], 'add', 11"
should be converted to a tuple: ([(1, 1), (2, 1)], 'add', 11)
.
So far, I tried:
tuples = []
for line in file:
tuples.append((line,))
But I am getting a string conversion
[("[(1,1),(2,1)], 'add', 11\n",), ("[(1,2),(1,3)], 'div', 2\n",), ("[(3,1),(4,1),(3,2),(4,2)], 'times', 240\n",), ("[(2,2),(2,3)], 'minus', 3",)]