- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
An Anagram I Am in Python
Suppose we have two strings s0 and s1, we have to check whether they are anagrams of each other or not. As we know two strings are said to be anagrams when we can rearrange one to become the other.
So, if the input is like s0 = "listen", s1 = "silent", then the output will be True.
To solve this, we will follow these steps −
sort the characters of s0 and s1
if sorted sequence of characters of s0 and s1 are same, then
return True
otherwise return False
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, s0, s1): return sorted(s0) == sorted(s1) ob = Solution() print(ob.solve("listen", "silent"))
Input
"listen", "silent"
Output
True
- Related Articles
- Valid Anagram in Python
- Identify me, who am I- I am a planet and I look like Earth"."
- Anagram checking in Python using collections.Counter()
- Anagram Substring Search using Python
- What is an anagram in C language?
- Anagram checking in Python program using collections.Counter()
- Python Program for Anagram Substring Search
- Program to find length of longest anagram subsequence in Python
- In college, if I am being ragged by my seniors, whom should I complain?
- Check if binary representations of two numbers are anagram in Python
- Check whether two strings are anagram of each other in Python
- Anagram Pattern Search
- Program to find minimum swaps required to make given anagram in python
- Despite being rich, why am I not able to get happiness?
- Check if any anagram of a string is palindrome or not in Python

Advertisements