-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCharTypeCount.py
48 lines (36 loc) · 1.2 KB
/
CharTypeCount.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def count_types(Astring):
Adict = {}
characters = '!"#$%&()*+,-./:;<=>?@[\]^_`{|}~'
characters0 = "'"
for item in Astring:
if item.isupper():
if "upper" not in Adict:
Adict["upper"]=1
else:
Adict["upper"]+=1
if item.islower():
if "lower" not in Adict:
Adict["lower"]=1
else:
Adict["lower"]+=1
if item.isnumeric():
if "numeral" not in Adict:
Adict["numeral"]=1
else:
Adict["numeral"]+=1
if item.isspace():
if "space" not in Adict:
Adict["space"]=1
else:
Adict["space"]+=1
if item in characters or item in characters0:
if "punctuation" not in Adict:
Adict["punctuation"]=1
else:
Adict["punctuation"]+=1
return Adict
#print (although the order of the keys may vary):
#{"lower": 7}
#{"upper": 3, "lower": 8, "punctuation": 1, "spaces": 4, "numerals": 3}
print(count_types("aabbccc"))
print(count_types("ABC 123 doe ray me!"))