File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 2323def tokenize (text : str ) -> Iterator [str ]: # <1>
2424 """return iterable of uppercased words"""
2525 for match in RE_WORD .finditer (text ):
26+ # for each word in phrase, group goes to string from re.Match object
2627 yield match .group ().upper ()
2728
2829def name_index (start : int = 32 , end : int = STOP_CODE ) -> dict [str , set [str ]]:
2930 index : dict [str , set [str ]] = {} # <2>
3031 for char in (chr (i ) for i in range (start , end )):
32+ # for each unicode character
3133 if name := unicodedata .name (char , '' ): # <3>
34+ # lookup English word name of character
3235 for word in tokenize (name ):
36+ # for each word in the name, add to dict with symbol in value set
3337 index .setdefault (word , set ()).add (char )
3438 return index
3539# end::CHARINDEX[]
40+
41+ if __name__ == '__main__' :
42+ index = name_index (32 , 65 )
43+ print (f"""
44+ SIGN: { sorted (index ['SIGN' ]) }
45+ DIGIT: { sorted (index ['DIGIT' ]) }
46+ DIGIT & EIGHT: { index ['DIGIT' ] & index ['EIGHT' ] }
47+ # & is a set operation
48+ """ )
You can’t perform that action at this time.
0 commit comments