Python Online Compiler
Example: Python program to find all the patterns of 0(1+)0 in the given string
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# Python program to find all the patterns of 0(1+)0 in the given string # @This function will find the pattern def findPattern(str): last, i, c = str[0], 1, 0 # c is the counter part while i < len (str): if str[i] == '1' and last == '0': while i < len (str) and str[i] == '1': i += 1 if i < len (str) and str[i] == '0': c += 1 last = str[i] if i < len (str) else last i += 1 return c # @It's the driver code print ("Enter the string: ", end="") str = str (input ()) print ("\nThe Number of patterns found: ", findPattern(str))
1001001001
Output
Clear
ADVERTISEMENTS