"""Word counting, with a docstring the queries pick out separately."""from__future__importannotationsimportrefromdataclassesimportdataclass,fieldfromtypingimportIterableWORD=re.compile(r"[A-Za-z']+")@dataclass(frozen=True)classCounter:"""Counts words, ignoring case."""counts:dict[str,int]=field(default_factory=dict)defadd(self,text:str)->None:formatchinWORD.finditer(text.lower()):word=match.group(0)self.counts[word]=self.counts.get(word,0)+1@propertydeftotal(self)->int:returnsum(self.counts.values())asyncdefgather(sources:Iterable[str])->Counter:counter=Counter()forsourceinsources:counter.add(source)returncounterif__name__=="__main__":# f-strings, numeric literals and a walrus.counter=Counter()counter.add("the quick brown fox")if(total:=counter.total)>0:print(f"{total=}{0x1F:d}{1_000_000}{3.14e-2!r}")else:raiseSystemExit("nothing counted")