So I wrote this code
def diagsDownRight(M):n = len(M)m = [[''] * (n - i - 1) + row + [''] * i for i, row in enumerate(M)]return ([''.join(col) for col in zip(*m)]), [''.join(col[::-1]) for col in zip(*m)]
def diagsUpRight(M):n = len(M)m = [['']*i + row + ['']*(n-i-1) for i, row in enumerate(M)]return [''.join(col) for col in zip(*m)], [''.join(col[::-1]) for col in zip(*m)]def rows(M):return ["".join(row) for row in M], ["".join(reversed(row)) for row in M]
def cols(M):return ["".join(col) for col in zip(*M)], [''.join(col[::-1]) for col in zip(*M)]
def contains_word(grid: list[list[str]], w: str):if w in diagsUpRight(grid):return wif w in diagsDownRight(grid):return wif w in rows(grid):return wif w in cols(grid):return wprint(contains_word(grid=[
["r","a","w","b","i","t"],
["x","a","y","z","c","h"],
["p","q","b","e","i","e"],
["t","r","s","b","o","g"],
["u","w","x","v","i","t"],
["n","m","r","w","o","t"]]
, w='raw'))
For this code, I want to let contains_word return the word w if it is found in either rows(M), cols(M), diagsDownRight(M), diagsUpRight(grid)but when I put in the code as shown above, the output doesn't show up. What am I doing wrong here?
Edit I tried doing this and still the output returns None
def contains_word(grid: list[list[str]], w: str):for col in diagsUpRight(grid):if w in col:return wfor col in diagsDownRight(grid):if w in col:return wfor row in rows(grid):if w in row:return wfor col in cols(grid):if w in col:return wprint(contains_word(grid=[["r","a","w","b","i","t"],
["x","a","y","z","c","h"],
["p","q","b","e","i","e"],
["t","r","s","b","o","g"],
["u","w","x","v","i","t"],
["n","m","r","w","o","t"]]
, w='raw'))