![]() ![]() ![]() The regex variant is likely faster than this for virtually all cases that do not involve huge dictionaries of potential suffixes that cannot be easily represented as a regex at least in cPython. The final one is probably significantly faster in pypy then cpython. Return lambda v: suffix_dict.get(v, lambda v: v)(v) Suffix_dict = helper( for s in suffix_dict], None) Return lambda v: v if v.endswith(suf) else v Remove_domain("") = "sub.abc"įor a collection of constant suffixes the asymptotically fastest way for a large number of calls: def remove_suffix_preprocess(*suffixes): Remove_suffix("abc.com", ".com") = 'abc'įor a regex: def remove_suffix_compile(suffix_pattern): ![]() You probably will want to use one of first 2 implementations however I have included the 3rd for completeness.įor a constant suffix: def remove_suffix(v, s): ![]() If you need to strip some end of a string if it exists otherwise do nothing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |