λμ λ리 = λΉλμ κΈ°λ‘
리μ€νΈ = μ λ ¬ν νν리μ€νΈ
μ²μμ for λ¬Έμ ν΅ν΄μ μλ¬Έμ λ¬Έμ νλμ© μ½μ΄μμ λμ λ리 κ°μ λμ μμΌμ€λ€.
ch κΈμ¨κ° μλμ§ νμΈνλ λ¬Έμ₯ => ch in countDic =>True False
λμ λ리λ₯Ό μ λ ¬ν΄μ€λ€ . νν -> 리μ€νΈλ‘ λ³ν
리μ€νΈ [a][b]
a μλ λ¬Έμ
b λ λΉλ μ
κ° μ μ₯λμ΄μμΌλ―λ‘ μΆλ ₯.
import operator
inStr = '''λ΄κ° λ΄κ°.. λ΄κ° κ·Έ μ΄λ¦μ λΆλ μλ λ΄κ° κ·Έ λμ§ .. μ΄λ¦μ λΆλ λ λ΄κ° κ·Έ μ΄λ¦μ
μκ³ μμλ λ΄κ° μ΄λ¦μ λΆλ λ€κ° λ§μλ€κ° μ΄λ¦μ...'''
countDic = {}
countList = []
if __name__ == "__main__":
for ch in inStr :
if 'γ±' <= ch and ch <='ν£':
if ch in countDic :
countDic[ch] +=1
else:
countDic[ch] = 1
countList= sorted(countDic.items(), key=operator.itemgetter(1), reverse = True)
print('μλ¬Έ\n' ,inStr)
print('---------')
print('λ¬Έμ λΉλμ')
print('---------')
for i in range(0, len(countList)):
print(countList[i][0], '\t', countList[i][1])