题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
import re
def my_func(in_str):
alphabet = len(re.findall("[a-zA-Z]+?", in_str))
white_space = len(re.findall("\s+?", in_str))
numbers = len(re.findall("[0-9]+?", in_str))
others = len(list(in_str)) - alphabet - white_space - numbers
print(alphabet, white_space, numbers, others, sep="\n")
while True:
try:
my_func(input())
except (EOFError, KeyboardInterrupt):
break
查看3道真题和解析