Buggy python submission (verdict: Runtime Error):
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    #matrix[i] = [0 if x == '.' else x for x in matrix[i]]
#print(matrix)
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            flag = 0
            for n in list([-1, 1]):
                i_n = i + n
                j_n = j + n
                if matrix[i_n][j] == '#' and i_n >= 0 and i_n < h:
                    flag = 1
                    break
                if matrix[i][j_n] == '#' and j_n >= 0 and j_n < w:
                    flag = 1
                    break
            if flag == 0:
                print('No')
                exit()
print('Yes')
#print(*matrix, sep = '\n')


Fixed submission:
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    #matrix[i] = [0 if x == '.' else x for x in matrix[i]]
#print(matrix)
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            flag = 0
            for n in list([-1, 1]):
                i_n = i + n
                j_n = j + n
                if i_n >= 0 and i_n < h:
                    if matrix[i_n][j] == '#':
                        flag = 1
                        break
                if j_n >= 0 and j_n < w:
                    if matrix[i][j_n] == '#':
                        flag = 1
                        break
            if flag == 0:
                print('No')
                exit()
print('Yes')
#print(*matrix, sep = '\n')

Buggy python submission (verdict: Runtime Error):
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    #matrix[i] = [0 if x == '.' else x for x in matrix[i]]
print(matrix)
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            flag = 0
            for n in list[-1, 1]:
                i_n = i + n
                j_m = j + m
                if matrix[i_n][j] == '#' and i_n >= 0 and i_n < h:
                    flag = 1
                    break
                if matrix[i][j_m] == '#' and j_m >= 0 and j_m < w:
                    flag = 1
                    break
            if flag == 0:
                print('No')
                exit()
print('Yes')
#print(*matrix, sep = '\n')


Fixed submission:
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    #matrix[i] = [0 if x == '.' else x for x in matrix[i]]
#print(matrix)
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            flag = 0
            for n in list([-1, 1]):
                i_n = i + n
                j_n = j + n
                if i_n >= 0 and i_n < h:
                    if matrix[i_n][j] == '#':
                        flag = 1
                        break
                if j_n >= 0 and j_n < w:
                    if matrix[i][j_n] == '#':
                        flag = 1
                        break
            if flag == 0:
                print('No')
                exit()
print('Yes')
#print(*matrix, sep = '\n')