Better way in Python to count string in another string

后端 未结 2 1084
滥情空心
滥情空心 2021-01-15 15:21

This code works, but reading posts on here I get the impression it is probably not a very \"Pythonic\" solution. Is there a better more efficient way to solve this specific

2条回答
  •  一整个雨季
    2021-01-15 16:13

    Another possible solution.

    >>> a= 'almforeachalmwhilealmleandroalmalmalm'
    >>> len(a.split('alm')) - 1
    6
    >>> q = "abcghabchjlababc"
    >>> len(q.split("abc")) - 1
    3
    

提交回复
热议问题