Дано:
''' +--+--+--+--+--+ | | | + + +--+--+--+ | | | | | | +--+--+--+--+--+ '''
Желаемое:
''' +-+-+-+-+-+ | | | + + +-+-+-+ | | | | | | +-+-+-+-+-+ '''
''' +--+--+--+--+--+ | | | + + +--+--+--+ | | | | | | +--+--+--+--+--+ '''
''' +-+-+-+-+-+ | | | + + +-+-+-+ | | | | | | +-+-+-+-+-+ '''
from re import findall def to_matrix(line: str) -> list: row_rgx = r"[\+\|].+(?<!\n|')" split_rgx = r"\+|\||--|\s{3}|\s{2}" wall = ['+', '--', '|'] out = [] for r in findall(row_rgx, line): a = [] for c in findall(split_rgx, r): if c in wall: a.append(1) else: a.extend([0] * (len(c) - 1)) out.append(a) return out if __name__ == '__main__': arr = '''\ +--+--+--+ | | | + + +--+ | | | | +--+--+--+''' print(*to_matrix(arr), sep='\n')