Enter a line of characters to count the number of letters, spaces, numbers, and other characters that contain English. Count the number of English alphabetic characters ' ' # -*- coding: utf-8 -*-import re# regular expression matching def ismathc (Src,pat): pattern = re.compile (PAT) result = re.match (PATTERN,SRC) if result == None: return 0 else: return 1# determine the type of individual character: Def chargetype (character) the three elements in the: # array represent English letters, numbers, and spaces, respectively type_num = [' [a-z]|[ A-z] ', ' \d ', ' \s '] # to determine whether the English alphabet if ismathc ( Character, type_num[0]) == 1: return 1     ELIF ISMATHC (character, type_num[1]) == 1: return 2 elif ismathc (character, type_num[2]) == 1: return 3 else: return 4def getcharnum (str): count = [] for i in range (4): count.append (0) Print (Len (count)) for i in range (Len (str)): if chargetype (Str[i]) ==1: count[0]+=1 elif chargetype (Str[i]) ==2: count[1]+=1 elif chargetype (Str[i]) ==3: count[2]+=1 else: count[3]+=1 return countstr= ' asc ss./ 124 ' Print ( Getcharnum (str))
Python Learning: Determining the number of alphanumeric spaces in a string