sw_1500 2020. 3. 30. 16:23



파이썬 Python


내 풀이

s = input().lower()
cnt = [0 for i in range(26)]
for i in s:
cnt[ord(i)-97] += 1
m = max(cnt)
if cnt.count(m) > 1:
print("?")
else:
print(chr(cnt.index(m)+65))


숏코딩

s = input().lower()
cnt = {c: s.count(c) for c in set(s)}
m = [k for k in cnt.keys() if cnt[k] == max(cnt.values())]
print(m[0]) if len(m) == 1 else print('?')

* 나는 주로 리스트를 사용하는 편인데, 숏코딩을 찾다가 dictionary를 사용한 코드를 보았다. 앞으로 dictionary도 많이 사용해야겠다.