• + 1 comment

    In Python 3, I recommend to use a dictionary to counts the number of repetitions for each integer. As many people have told, the number of possible different pairs if a number is repeated N times is N*(N-1), not over 2 as the combinatory coefficient nCr is, because one must count twice, i.e. (0,1) and (1,0).

    def solve(a):
        # Write your code here
        a_dic = {}
        pairs = 0
        #loop to count the number of elements
        for i in range(len(a)):
            if a[i] not in a_dic:
                a_dic[a[i]] = 0 #{a[i]:0}
            a_dic[a[i]] += 1 #{a[i]:+1} add one
        #loop for check whats integers taht are more than once
        for k in a_dic:
            val = a_dic[k]
            if val > 1: #condition more than once
                pairs += val * (val-1)  #possible pairs n*(n-1)
        return pairs