Count pairs with a sum

Write count_pairs(nums, target) that returns how many pairs of positions i < j have nums[i] + nums[j] == target. Repeated values make separate pairs.

count_pairs([1, 5, 7, -1, 5], 6)  ->  3     (1,5) (7,-1) (1,5)
count_pairs([1, 1, 1, 1], 2)      ->  6

The point is to practise counting complements with a dictionary as you go. One check has a hundred thousand numbers.

def count_pairs(nums, target):
    ...