2 comments
> _canonicalize_table = str.maketrans(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ_.",
"abcdefghijklmnopqrstuvwxyz--",
)<p>> ...<p>> value = name.translate(_canonicalize_table)<p>> while "--" in value:<p>> value = value.replace("--", "-")<p>translate can be wildly fast compared to some commonly used regexes or replacements.
I am curious, why not .lower().translate('_.', '--')
I would expect however that a regex replacement would be much faster than your N^2 while loop.
It would be, if it was a common situation.<p>This loop handles cases like `eggtools._spam` → `eggtools-spam`, which is probably rare (I guess it’s for packages that export namespaced modules, and you probably don’t want to export _private modules; sorry in advance for non-pythonic terminology). Having more than two separator characters in a row is even more unusual.
Previously: <a href="https://news.ycombinator.com/item?id=46557542">https://news.ycombinator.com/item?id=46557542</a>