Python sorted () to check if two strings are anagram or not

Python Methods and Functions | String Variables


 Input: s1 = "listen" s2 = "silent" Output: The strings are anagrams. Input: s1 = "dad" s2 = "bad" Output: The strings aren't anagrams. 

Python provides a built-in function

# function to check if there are two lines
# anagram or not

def check (s1, s2) :


# sorted lines are checked

  if ( sorted (s1) = = s orted (s2)):

print ( "The strings are anagrams."

else :

print ( "The strings aren't anagrams."

# driver code

s1 = "listen"

s2 = "silent"  
check (s1, s2)


 The strings are anagrams.