Python: Anagram check program



 def anagram(s1, s2):

    #s1 and s2 are two strings which are to be checked for anagram
    s1 = s1.replace(' ', '').lower() # s1 is reaasigned with removing spaces and then made all lowercase 
    s2 = s2.replace(' ', '').lower() # s2 is reaasigned with removing spaces and then made all lowercase
    return sorted(s1) == sorted(s2)  # sorted both s1 and s2 and checked, if equal then returns True else False

print(anagram('this is right', 'is this right')) #printed True for anagram and False for not anagram

Output:
>>True

Comments

Popular posts from this blog

Continuous Wave Radar

Digital design fundamentals

Frequency Modulated Continuous Wave Radar