I'm trying to write a code which returns ALL indices of the elements from a list, which are repeated EXACTLY TWICE. I'm having trouble with my own algorithm. My code only returns the FIRST occurrence it finds. I want this fixed. Here's my own code (it's somehow weird, I know):
from collections import Counter
length = int(input())
user_input = [int(x) for x in input().split()]
occurrances = Counter(user_input)
check_list = []
check_list.append(list(occurrances.keys())[list(occurrances.values()).index(2)])
print(check_list)
I appreciate any help from anyone. Thanks in advance.