Better way in Python to count string in another string

后端 未结 2 1092
滥情空心
滥情空心 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:16

    Why not use the count method of str?

    >>> a = "abcghabchjlababc"
    >>> a.count("abc")
    3
    

提交回复
热议问题