Anagram

Last updated: 29th Aug, 2020

  

Problem Statment

Two strings a and b consisting of lowercase characters are given.
Check whether two given strings are an anagram of each other or not.
Note: An anagram of a string is another string that contains the same characters, only the order of characters can be different.


Input Format
a = "restful"
b = " fluster "

Output Format
True
Approach :

1.Check the length of the both strings
2.Check each alphabet of the both strings
3.Return True if both a and b string are equal else return False

Python Code

def isAnagram(a,b):
    #check the length of the both strings 
    if len (a)!=len (b):
        return False
    #sort the both strings    
    a= sorted(a)
    b=sorted(b)
                             
    #check each letter is equal or not 
    for i in range(0,len(a)):
        if a[i]!= b[i]:
            return False
    return True
                         
print(isAnagram("restful" , "fluster"))