Python: Count overlapping substring in a string

后端 未结 5 1279
情歌与酒
情歌与酒 2020-12-11 09:36

Say I have string = \'hannahannahskdjhannahannah\' and I want to count the number of times the string hannah occurs, I can\'t simply use count, bec

5条回答
  •  隐瞒了意图╮
    2020-12-11 10:08

    If you want to count also nonconsecutive substrings, this is the way to do it

    def subword(lookup,whole):
        if len(whole)

提交回复
热议问题