I have a text file that contains 4 sets of numbers demarcated by square brackets: [-114.63332, -114.63349, -114.63423, …,-114.63305][-103.55583, -104.00265, -104.64165, -105.14679, …, -106.63325, -106.61103][-109.04984, -109.06017, -109.06015, …, -109.0498][-114.04392, -114.04391, -114.04375, -114.04195, …, -114.04558]
I need to extract the sets and assign names to each set: a_lon, b_lon, c_lon, d_lon I have read in the text file and create a regex pattern to match:
with open('x_lons.txt', 'r') as f:
x_lons = f.read()
print(type(x_lons))
which returns class 'str'
match = re.compile(r'(\[.*?\])')
for m in re.finditer(match, x_lons):
print(m.groups())
which returns match object that prints:
('[-114.63332, -114.63349, -114.63423, …,-114.63305]',)
('[-103.55583, -104.00265, -104.64165, -105.14679, …, -106.63325, -106.61103]')
('[-109.04984, -109.06017, -109.06015, …, -109.0498]',)
('[-114.04392, -114.04391, -114.04375, -114.04195, …, -114.04558]',)
I have also run a re.split to get similar output without the "()" brackets
At this point I am unable to determine how to assign names to each number set matched by the pattern. I can see the sets in the print() but unable to determine to get the sets assigned to names.