fork download
  1. def find_words_position(s):
  2.  
  3. start = 0
  4. for word in str.split(s):
  5.  
  6. start = str.find(s, word, start)
  7. yield word, start, start + len(word)
  8.  
  9.  
  10. print(tuple(find_words_position("one two three")))
  11. print(tuple(find_words_position("one one one")))
  12.  
Success #stdin #stdout 0.02s 8736KB
stdin
Standard input is empty
stdout
(('one', 0, 3), ('two', 4, 7), ('three', 8, 13))
(('one', 0, 3), ('one', 0, 3), ('one', 0, 3))