Assuming file.txt exists with the following contents:
(0, 0), (0, 2), (0, 4), (-1, -1), (0, -2), (1, -1), (-1, -3) (-1, 1), (-1, 3), (1, 1), (1, 3), (1, 5), (2, 0), (2, 2), (3, 3), (2, 4), (3, 5), (4, 4), (5, 3), (6, 4), (5, 5), (7, 5)
You can use literal_eval() for each line in the loop and expand the resulting list:
from ast import literal_eval result = [] with open('file.txt', 'r') as f: for line in f: result.extend(literal_eval(line.strip())) print result
prints:
[(0, 0), (0, 2), (0, 4), (-1, -1), (0, -2), (1, -1), (-1, -3), (-1, 1), (-1, 3), (1, 1), (1, 3), (1, 5), (2, 0), (2, 2), (3, 3), (2, 4), (3, 5), (4, 4), (5, 3), (6, 4), (5, 5), (7, 5)]
FYI, literal_eval () is safe:
It is safe to evaluate a node expression or a string containing a Python expression. The string or node provided can only consist of the following Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None.
Hope this helps.