我在阅读文档时遇到了 Python str.count
函数。我似乎找不到关于函数内部工作的任何好的解释。什么算法用于计算字符串中子串的数量?它实际上是如何工作的?
最佳答案
在 https://github.com/python/cpython/blob/master/Objects/stringlib/fastsearch.h 研究源代码
文件顶部的评论解释了这一点:
fast search/count implementation, based on a mix between boyer- moore and horspool, with a few more bells and whistles on the top. for some more background, see: http://effbot.org/zone/stringlib.htm
关于python - 用于实现 Python str.count 函数的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16806972/