Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. def searcher(word: str, text: str, num: int = 1):
  2.  
  3. global startindex
  4. global size
  5. global rflag
  6.  
  7. if num == 1 and text.count(word) == 1:
  8. startindex = text.find(word);
  9. size = len(word);
  10. rflag = "word start from " + str(startindex + 1) + " and end in " + str(size + startindex)
  11. elif num > 1 and text.count(word) <= num:
  12. startindex = 0
  13. for i in range(num):
  14. startindex = text.find(word, startindex)
  15. size = startindex + len(word)
  16. rflag = "word start from " + str(startindex + 1) + " and end in " + str(size + startindex)
  17.  
  18. return rflag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement