Simple solution
\n# Code\npython3 []\ndef get_all_nums(num, swaps_left, to_be_paired, seen): # get all nums creatabel from num that are in the set of pairs that can be matched\
\n# Code\n```python3 []\ndef get_all_nums(num, swaps_left, to_be_paired, seen): # get all nums creatabel from num that are in the set of pairs that can be matched\n    #O(N^5), N = 7\n    if swaps_left == 0:\n        num_int = int("".join(num))\n        #print("L5", num_int)\n        if num_int  in to_be_paired and  num_int not in seen:\n            seen.add(num_int)\n            return to_be_paired[num_int] # return count of matches\n        else:\n            return 0\n    else:\n\n        ans = get_all_nums(num, swaps_left-1,to_be_paired,seen) # do no swap case\n        for i in range(len(num)):\n            for j in range(i+1,len(num)):\n                num[i], num[j] = num[j],num[i] # swap\n                ans += get_all_nums(num, swaps_left - 1,to_be_paired, seen)\n                num[i], num[j] = num[j],num[i] # backtrack\n        return ans \n\n\nclass Solution:\n    def countPairs(self, nums: List[int]) -> int:\n        ct = {} # ct of pairs matched for each num in nums\n        max_dig_size = 0\n        for n in nums:\n            #ct[n] = 0\n            max_dig_size = max(max_dig_size, len(str(n)))\n\n        to_be_paired = collections.Counter(nums)\n        ans = 0\n        for num in nums:\n            lnum = ["0"]* (max_dig_size - len(str(num))) + list(str(num))\n\n            # remove form seen so that we dont overcount\n            to_be_paired[num] -= 1\n            if to_be_paired[num] == 0:\n                to_be_paired.pop(num)\n            \n            ans +=  get_all_nums(lnum,2, to_be_paired, set([]))\n            #print(n, num)\n\n        return int(ans)\n\n```
['Python3']