from collections import Counter
my_str = 'dfdefdgf'
data_dict = dict(Counter(sorted(my_str)))
all_values = data_dict.values()
max_value = max(all_values)
answer = ''.join( [key for key in list(data_dict.keys()) if max_value is data_dict[key]] )
print(answer)
collections의 Counter 함수는 list 함수를 입력으로 받아서 dict 형태로 출력을 한다.
이때 key 값을 list의 element 값
value 값은 element의 중복 수 이다.
이 특징을 잘 이용하면 직관적으로 풀기 쉽다.
'Program > Python' 카테고리의 다른 글
for-else 문 (0) | 2022.08.02 |
---|---|
itertools의 순열(permutation), 조합(combination) (0) | 2022.08.02 |
Sinc 함수 구현 (0) | 2021.05.06 |
K번째 큰 수 (0) | 2021.05.06 |
람다 표현식 (0) | 2021.04.24 |