Tag: occurrence
Python : Find occurrence count & all indices of a sub-string in another string | including overlapping sub-strings
In this article we will discuss different ways to count occurrences of a sub-string in another string and also their index positions. Count occurrences of a sub-string in another string using string.count() Python’s String class contains a method to count the non overlapping occurrences of a sub-string in the string object i.e. string.count(s, sub[, start[, …
Replace first occurrence of a substring in Python
In this article, we will discuss different ways to replace the first occurrence of a substring from a string in Python. Suppose we have a string, “This is the last rain of Season and Jack is here.” In this string, the substring “is” occurs at 3 different places. But we want to replace only the …
Replace Last occurrence of a String in Python
This article will discuss different ways to replace only the last occurrence of a substring in a string. Table Of Contents Using replace() function. Using rfind() function Using rsplit() and join() Suppose we have a string, Advertisements “This is the last rain of Season and Jack is here.” We want to replace the last occurrence …
Count occurrence of an item in List in Python
In this article, we will discuss different ways to count the occurrence of an item in a List in Python. Table Of Contents Count occurrence of an item in List using count() method Count occurrence of an item in List using for loop Count occurrence of an item in List using operator Count occurrence of …