
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program for array rotation
In this article, we will learn about the solution to the problem statement given below.
Problem statement − Given a text and a pattern, we need to print all occurrences of pattern and its permutations (or anagrams) in text.
Now let’s observe the solution in the implementation below −
Example
# maximum value MAX = 300 # compare def compare(arr1, arr2): for i in range(MAX): if arr1[i] != arr2[i]: return False return True # search def search(pat, txt): M = len(pat) N = len(txt) # countP pattern account # countTW text window count countP = [0]*MAX countTW = [0]*MAX for i in range(M): (countP[ord(pat[i]) ]) += 1 (countTW[ord(txt[i]) ]) += 1 # Traversal for i in range(M, N): # Compare current window and patten counts if compare(countP, countTW): print("Found at Index", (i-M)) # Add charcter to window (countTW[ ord(txt[i]) ]) += 1 # remove charcter from window (countTW[ ord(txt[i-M]) ]) -= 1 # Check for the last window if compare(countP, countTW): print("It is Found at Index : ", N-M) # main txt = "TUTORIALSPOINT" pat = "TOR" search(pat, txt)
Output
Found at Index 2
All the variables are declared in the local scope and their references are seen in the figure above.
Conclusion
In this article, we have learned about how we can make a Python Program for Anagram Substring Search.
- Related Articles
- Python Program for Reversal algorithm for array rotation
- C Program for Program for array rotation?
- Java Program for array rotation
- Golang Program For Array Rotation
- C Program for Reversal algorithm for array rotation
- Java Program for Reversal algorithm for array rotation
- JavaScript Program for Reversal algorithm for array rotation
- JavaScript Program for Block swap algorithm for array rotation
- JavaScript Program for Reversal algorithm for right rotation of an array
- Reversal Algorithm for Array Rotation using C++
- JavaScript Program for Left Rotation and Right Rotation of a String
- Block swap algorithm for array rotation in C++
- JavaScript Program for Clockwise rotation of Linked List
- Reversal Algorithm for Right Rotation of an Array using C++
- Program to find how many distinct rotation groups are there for a list of words in Python

Advertisements