Skip to content

Commit

Permalink
定义函数countchar()按字母表顺序统计字符串中所有出现的字母的个数
Browse files Browse the repository at this point in the history
  • Loading branch information
BuglessCoder authored Apr 9, 2018
1 parent 08de248 commit 8ffee86
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions countchar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'''
Created on 2018年4月9日
@author: lidawei
'''
def countchar(str):
charDict={}
for i in range(26):
charDict[chr(i+65)]=0
str=str.upper()
for x in str:
if ord('A')<=ord(x)<=ord('Z'):
charDict[x]+=1
else:
continue
return [charDict[chr(i+65)] for i in range(26)]

if __name__ == "__main__":
print(countchar(input()))

0 comments on commit 8ffee86

Please sign in to comment.