Предположим, что ваш входной файл выглядит примерно так (матрицы разделены пустой строкой):
2,4,5
4,7,3
1,2
5,9
1,6
Этот код Python (для python3):
input_file = open('input.txt', 'r')
a = []
b = []
current = a # Current will point to the current matrix
for line in input_file.readlines():
if ',' not in line: # This is our separator - a line with no ',', switch a matrix
current = b
else:
current.append([]) # Add a row to our current matrix
for x in line.split(','): # Values are separated by ','
current[len(current) - 1].append(int(x)) # Add int(x) to the last line
print(a, b)
input_file.close()
Выводитследующее:
[[2, 4, 5], [4, 7, 3]] [[1, 2], [5, 9], [1, 6]]