𝘼𝙣𝙖𝙡𝙮𝙨𝙞𝙨/ᴀʟɢᴏʀɪᴛʜᴍ

Collections 최빈값 모듈 - most_common

콜라맛갈비 2023. 6. 19. 14:25
728x90

 

collections.Counter(a).most_common(n)   

: a의 요소를 세어, 최빈값 n개를 반환합니다. (리스트에 담긴 튜플형태로)

 

from collections import Counter
def solution(array):
    data = Counter(array).most_common(2)
    print(data)
    
    #입력값 	[1, 2, 3, 3, 3, 4]
    #출력값 	[(3, 3), (1, 1)]
728x90