I'm trying to accumulate a list of indices of items that occur multiple times, given a list. Not sure how to go about doing that as my code only manages to compare pattern[1] and pattern[2] before terminating.
def test(pattern):
"""(list) -> list of int
>>> test(['A', 'B', 'A', 'C', 'A'])
[0, 2, 4]
>>> test(['A', 'B'])
[]
"""
indices = []
new_list = []
for i in range(len(pattern) - 1):
if pattern[i][-1] == pattern[i + 1]:
indices.append(i)
new_list = phoneme_list[max(indices):]
return new_list