DEV Community

Sivakumar Mathiyalagan
Sivakumar Mathiyalagan

Posted on

Finding the given word

Question:
In this sentence 'My favourite cricketer is Dhoni, Kohli and Rohit' find the word 'Dhoni'

Code:

word = 'My favourite cricketer is Dhoni, Kohli and Rohit'
key = 'dhoni'
word = word.lower()

key_length = len(key)
print(key_length)
word_length = len(word)

for i in range(word_length):
    if key == word[i:i+key_length]:
        print('found')
        break

else :
   print("not found")
Enter fullscreen mode Exit fullscreen mode

Output:

Top comments (0)