As I mentioned in comments, you need permutations
instead of combinations
from itertools
. Below code works. And if your aim is to simply get a dictionary of count, you can simply do dict(Counter(...))
to convert it into dict.
Also, removed some unnecessary code lines.
from collections import Counter
from itertools import permutations
def findPairs(n):
###
pair_counts = dict()
count = dict(Counter(permutations(n, 2)))
print(count)
nums = [2,3,7]
findPairs(nums)
# Output
# {(2, 3): 1, (2, 7): 1, (3, 2): 1, (3, 7): 1, (7, 2): 1, (7, 3): 1}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…