def multi_find(source, target, start, end): '''Finds all occurrences of the substring target in the string source, within the range start <= pos < end. Returns a comma-separated string of values.''' result = '' pos = start while pos < end: next_pos = source.find(target, pos, end) if next_pos == -1: break result += (str(next_pos) + ',') pos = next_pos + 1 if result == '': return result return result[:-1]