Answers for "anagrams python"

3

python anagrams

# function to check if two strings are 
# anagram or not  
def check(s1, s2): 
      
    # the sorted strings are checked  
    if(sorted(s1)== sorted(s2)): 
        print("The strings are anagrams.")  
    else: 
        print("The strings aren't anagrams.")          
          
# driver code   
s1 ="listen"
s2 ="silent" 
check(s1, s2)
Posted by: Guest on May-13-2020
8

anagram python

def isAnagram(A,B):
  if sorted(A) == sorted(B):
    print("Yes")
  else:
    print("No")
isAnagram("earth","heart") #Output: Yes

#Hope this helps:)
Posted by: Guest on February-21-2021
0

anagrams python

from collections import defaultdict

def findAnagrams(input_str):
    anagram = defaultdict(list)

    for word in input_str:
        anagram[str(sorted(word))].append(word)
    return list(anagram.values())
Posted by: Guest on April-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language