Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Walrus, zip_longest solution in Clear category for The Hidden Word by Sioul
from itertools import zip_longest
def find(matrix, word):
for i, row in enumerate(matrix):
if word in row:
return i, row.index(word)
def checkio(text, word):
matrix = text.replace(' ', '').lower().splitlines()
if a := find(matrix, word): # walrus operator!
return [a[0]+1, a[1]+1 , a[0]+1, a[1]+len(word)]
tmatrix = [''.join(row) for row in zip_longest(*matrix, fillvalue=' ')]
if b := find(tmatrix, word): # walrus operator!
return [b[1]+1 , b[0]+1, b[1]+len(word), b[0]+1]
Dec. 10, 2019
Comments: