def findsubstr(text, substr): """findsubstr(text, substr) - returns an iterator of positions of substr within text""" position = e.text.find(substr) while position != -1: yield position position = e.text.find(substr, position+1)