class UserMainCode(object):

    @classmethod
    def range(cls, input1, input2):
        pass

Example:

  • input1: (1,1,2)

  • input2: 3

  • Output: {1}

1

There are 1 best solutions below

0
lepsch On

The following code below would do the trick. It uses the collections .Counter to count all items in the list/tuple. The code also uses the new type hinting from Python 3 to enable static analysis.

from collections import Counter


class UserMainCode:
    @classmethod
    def range(cls, input1: list[int], input2: int) -> list[int]:
        input = input1[0:input2 + 1]
        counter = Counter(input)
        return [
            x for x, count in counter.items()
            if count == 2
        ]


print(UserMainCode.range((1, 1, 2, 3, 3), 5))
# Prints: [1, 3]

It's also possible to eliminate input2 entirely as lists/tuples/dicts... have the length read by the function len