리스트를 다루는 방법을 익히기 좋은 문제이다.
# 단어 공부
# lower()-소문자로 저장 / upper()-대문자로 저장
words = list(input().upper())
# 중복 제거한 리스트
unique_words = list(set(words))
cnt_list =[]
# unique_words에 있는 알파벳 하나씩 원래 문장(words)에서 개수 세기
for i in unique_words:
cnt = words.count(i)
cnt_list.append(cnt) # 각 알파벳 개수 append
if cnt_list.count(max(cnt_list)) > 1:
print('?')
else:
max_index = cnt_list.index(max(cnt_list))
print(unique_words[max_index])
[핵심 코드]
words = list(input().upper())
-> upper함수
unique_words = list(set(words))
-> set함수로 중복을 제거한 후 다시 list로 형변환
max_index = cnt_list.index(max(cnt_list))
-> cnt_list에서 최댓값의 index를 가져오는 법
'백준 - 파이썬 > 단계별 - 6 (심화1)' 카테고리의 다른 글
*[백준/파이썬] 25206번 너의 평점은 (0) | 2025.05.09 |
---|---|
[백준/파이썬] 1316번 그룹 단어 체커 (0) | 2025.05.09 |
*[백준/파이썬] 2941번 크로아티아 알파벳 (1) | 2025.05.09 |
*[백준/파이썬] 2444번 별 찍기 - 7 | 반복문 거꾸로 돌리기 (0) | 2025.05.07 |