배운 것/Python

[python] 문자열에서 알파벳 갯수 카운트

ㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇ! 2018. 5. 4. 11:25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
string = input("영어 문자열 입력 : ")
 
def printcount(i):
    global string
    cnt = string.count(chr(i))
    if cnt is not 0:
        print(chr(i)," : ",cnt)
        
for i in range(65,91):
    printcount(i)
print("-------------------------------------")
for i in range(97,123):
    printcount(i)
    
 
cs