from typing import List def repeats(L: List[int]) -> List[int]: """Returns a sorted list of unique elements that are present in L more than once.""" return list(sorted({x for x in L if L.count(x) > 1})) def testRepeats(): print("Testing repeats()...", end="") assert repeats([1, 2, 3, 2, 1]) == [1, 2] assert repeats([1, 2, 3, 2, 2, 4]) == [2] assert repeats([1, 5, 3, 5, 2, 3, 2, 1]) == [1, 2, 3, 5] assert repeats([7, 9, 1, 3, 7, 1]) == [1, 7] assert repeats(list(range(100))) == [] assert repeats(list(range(100)) * 5) == list(range(100)) # Verify that the function is nonmutating: L = [1, 2, 3, 2, 1] repeats(L) assert L == [1, 2, 3, 2, 1] print("Passed!") def main(): testRepeats() main()