def get_indices(text, substr): '''Return a list containing the indices where str substr appears in str text. Overlapping instances of substr should be counted. For example, get_indices("abcabcabc", "bc") --> [1, 4, 7] get_indices("bbbbbbb", "bb") --> [0, 1, 2, 3, 4, 5]''' # This version is incorrect! index = 0 indices = [] while index != -1: indices.append(text.find(substr, index)) index = text.find(substr, index + 1) return indices if __name__ == "__main__": print get_indices("abcabcabc", "bc"), "sb", [1,4,7] print get_indices("bbbbbbb", "bb"), "sb", [0,1,2,3,4,5] print get_indices("bbbbbbb", "aa"), "sb", [] print get_indices("abc", "abcde"), "sb", [] print get_indices("", ""), "sb", [0] print get_indices("abcabcabc", "ab"), "sb", [0,3,6]