Check If a Word Occurs As a Prefix of Any Word in a Sentence LeetCode solution in Python
1class Solution(object):2def isPrefixOfWord(self, sentence, searchWord):3"""4:type sentence: str5:type searchWord: str6:rtype: int7"""8word_list = sentence.split()9counter = 010for word in sentence.split():11counter += 112if searchWord == word[0 : len(searchWord)]:13return counter14return -1