Algorithm used to implement the Python str.count function

前端 未结 1 1065
深忆病人
深忆病人 2021-01-13 18:13

I came across the Python str.count function while reading the documentation. I can\'t seem to find any good explanation on the inner working of the function. Wh

相关标签:
1条回答
  • 2021-01-13 18:41

    Study the source code at https://github.com/python/cpython/blob/master/Objects/stringlib/fastsearch.h

    A comment at the top of file explains this much:

    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

    0 讨论(0)
提交回复
热议问题