Use re.sub instead of looping over re.findall

This commit is contained in:
Grant Sanderson 2023-01-04 13:02:16 -08:00
parent bf5d587204
commit c30b102458

View file

@ -18,8 +18,7 @@ def num_tex_symbols(tex: str) -> int:
rf"(\\{s})" + r"(\{\w+\})?(\{\w+\})?(\[\w+\])?" rf"(\\{s})" + r"(\{\w+\})?(\{\w+\})?(\[\w+\])?"
for s in ["begin", "end", "phantom"] for s in ["begin", "end", "phantom"]
) )
for tup in re.findall(pattern, tex): tex = re.sub(pattern, "", tex)
tex = tex.replace("".join(tup), " ")
# Progressively count the symbols associated with certain tex commands, # Progressively count the symbols associated with certain tex commands,
# and remove those commands from the string, adding the number of symbols # and remove those commands from the string, adding the number of symbols