Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
The Hidden Word solution in Uncategorized category for The Hidden Word by vvm70
def checkio(text, word):
s = text.lower().replace(' ', '').split('\n')
w = [(s.index(x) + 1, x.find(word) + 1, s.index(x) + 1, x.find(word) + len(word)) for x in s if word in x]
if w:
return w[0]
else:
for i in range(len(s) - len(word) + 1):
for c in range(len(s[i])):
if s[i][c] == word[0] and all([len(s[i+j]) > c for j in range(len(word))]):
if ''.join([x for j in range(len(word)) for x in s[i+j][c]]) == word:
return i + 1, c + 1, i + len(word), c + 1
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
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]
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]
May 28, 2020