I recently started studying Python on my own, and I have not been able to answer this question:
"Write a function that receives a list of names (as strings). The function returns a list of all the names that appear twice in a row in the list, without duplicates. For example, for the list: ["avi", "avi", "beni", "shlomo", "shlomo", "David", "haim", "moshe", "shlomo", "shlomo"] The function will return a list of Avi and Shlomo. The function must work in O (n)."
This is what I have written so far, but I have not succeeded:
def double_names(lst):
new_lst = []
for i in lst:
if lst[i] == lst[i+1]:
new_lst.append(i)
return new_lst
print(double_names(["avi", "avi", "beni", "shlomo", "shlomo", "David", "haim", "moshe", "shlomo", "shlomo"]))