View Single Post
Old 02-22-2025, 04:27 PM   #77
lomkiri
Groupie
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 167
Karma: 1497966
Join Date: Jul 2021
Device: N/A
To maxthegold and moldy:

In that way, you'll call the function capitalize() a lot, and you create 2 more tests in the loop, it's more efficient to modify directly the dict, automatically adding in it the capitalized form. In this way, you call the function only once for each word, at the initialization, it will be more efficient (and quicker on big ebooks).

And, as I put the possibility of capitalization as a parameter (True by default), I prefer not to put this test in the loop but in the init, for the same reason.

Furthermore, if "Paul" (for example) is in your dict, your code will search twice for it ("Paul" == "Paul".capitalize()), which is not the case in the code I propose.

Of course, the regex for those words, if provided, will be the same for lower case and capitalized case. If you don't want that for some words, put explicitly both forms in the dict

I have modified the code in the message 63 to include this feature. I also added a counter with the number of entries including the capitalized words in the dict.

Last edited by lomkiri; 02-22-2025 at 07:51 PM.
lomkiri is offline   Reply With Quote