 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if strings are rotations of each other or not in Python
Suppose we have two strings s and t, we have to check whether t is a rotation of s or not.
So, if the input is like s = "hello", t = "llohe", then the output will be True.
To solve this, we will follow these steps −
- if size of s is not same as size of t, then- return False
 
- temp := s concatenate with s again
- if count of t in temp > 0, then- return True
 
- return False
Let us see the following implementation to get better understanding −
Example Code
def solve(s, t): if len(s) != len(t): return False temp = s + s if temp.count(t)> 0: return True return False s = "hello" t = "llohe" print(solve(s, t))
Input
"hello", "llohe"
Output
True
Advertisements
 