from collections import Counter arr1 = [1, 1, 2, 3, 3, 3] arr2 = [3, 3, 3, 3, 3, 3] print(Counter(arr1)) # 출력: Counter({3: 3, 1: 2, 2: 1}) print(Counter(arr1) - Counter(arr2)) # 출력: Counter({1: 2, 2: 1})
import collections arr1 = [1, 1, 2, 3, 3, 3] arr2 = [3, 3, 3, 3, 3, 3] print(collections.Counter(arr1)) # 출력: Counter({3: 3, 1: 2, 2: 1}) print(collections.Counter(arr1) - collections.Counter(arr2)) # 출력: Counter({1: 2, 2: 1})
from collections import Counter arr = [1, 1, 2, 3, 3, 3] print(Counter(arr).most_common(2)) # 최빈값 2개 반환 # 출력: [(3, 3), (1, 2)]
import collections arr = [1, 1, 2, 3, 3, 3] print(collections.Counter(arr).most_common(2)) # 최빈값 2개 반환 # 출력: [(3, 3), (1, 2)]