Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Hidden Word by Sarina
from itertools import zip_longest
def checkio(text, word):
text_line = text.lower().replace(' ','').splitlines()
text_column = [''.join(item) for item in zip_longest(*text_line, fillvalue='-')]
# Search in lines
for line_num, line in enumerate(text_line, 1):
pos = line.find(word)
if pos != -1:
return [line_num, pos+1 ,line_num, pos+len(word)]
# Search in columns
for column_num, col in enumerate(text_column, 1):
pos = col.find(word)
if pos != -1:
return [pos+1, column_num , pos+len(word), column_num]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("""He took his vorpal sword in hand:
Long time the manxome foe he sought--
So rested he by the Tumtum tree,
And stood awhile in thought.
And as in uffish thought he stood,
The Jabberwock, with eyes of flame,
Came whiffling through the tulgey wood,
And burbled as it came!""", "noir") == [4, 16, 7, 16]
assert checkio("""DREAMING of apples on a wall,
And dreaming often, dear,
I dreamed that, if I counted all,
-How many would appear?""", "ten") == [2, 14, 2, 16]
Feb. 29, 2020
Comments: