• + 5 comments

    My solution:

    # Get the text from matrix
    text = [line[i] for i in range(m) for line in matrix]
    text = ''.join(text)
    # Find and replace
    pattern = r'([A-Za-z0-9])[!@#$%&\s]+(?=[A-Za-z0-9])'
    text = re.sub(pattern,r'\1 ', text)
    print(text)