logoalt Hacker News

teaearlgraycoldtoday at 1:54 AM1 replyview on HN

I would expect however that a regex replacement would be much faster than your N^2 while loop.


Replies

notpushkintoday at 2:37 AM

It would be, if it was a common situation.

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.