[프로그래머스] 시소 짝궁

 

문제

from collections import Counter
from itertools import combinations, permutations

def solution(weights):
    answer = 0
    
    cnt = Counter(weights)
    
    for k, v in cnt.items():
        if v > 1:
            answer += v * (v-1) // 2
        if k * 2 in cnt.keys():
            answer += v * cnt[k * 2]
        if k * 3 % 2 == 0 and k * 3 // 2 in cnt.keys():
            answer += v * cnt[k * 3 // 2]
        if k * 4 % 3 == 0 and k * 4 // 3 in cnt.keys():
            answer += v * cnt[k * 4 // 3]
    return answer