To Count The Occurrence Of One String In Other String In Python
If this is the first string : ABCD if this is the second string: ABCD is ABCD I want to count the occurrence of first string in the second string and that too in python. How can I
Solution 1:
Use str.count()
:
>>> str1 = "ABCD"
>>> str2 = "ABCD is ABCD"
>>> str2.count(str1)
2
Post a Comment for "To Count The Occurrence Of One String In Other String In Python"