Question

In: Computer Science

Write a function which takes two words as string arguments and checks whether they are anagrams...

Write a function which takes two words as string arguments and checks whether they are anagrams

NB: Please use spider in anaconda(python) and include a picture of the code

Solutions

Expert Solution

# function to check whether two strings are anagram
# of each other
 
 
def areAnagram(str1, str2):
    # Get lengths of both strings
    n1 = len(str1)
    n2 = len(str2)
 
    # If lenght of both strings is not same, then
    # they cannot be anagram
    if n1 != n2:
        return 0
 
    # Sort both strings
    str1 = sorted(str1)
    str2 = sorted(str2)
 
    # Compare sorted strings
    for i in range(0, n1):
        if str1[i] != str2[i]:
            return 0
 
    return 1
 
 
# Driver code
str1 = input("Enter first string: ")
str2 = input("Enter second string: ")
 
# Function Call
if areAnagram(str1, str2):
    print("\nThe two strings are anagram of each other")
else:
    print("\nThe two strings are not anagram of each other")

PLEASE LIKE THE SOLUTION :))

IF YOU HAVE ANY DOUBTS PLEASE MENTION IN THE COMMENT


Related Solutions

Write a function which takes two words as string arguments and checks whether they are anagrams.
Write a function which takes two words as string arguments and checks whether they are anagrams.
Write a function that takes a string as an argument checks whether it is a palindrome....
Write a function that takes a string as an argument checks whether it is a palindrome. A palindrome is a word that is the same spelt forwards or backwards. Use similar naming style e.g. name_pal. E.g. If we call the function as abc_pal(‘jason’) we should get FALSE and if we call it a abc_pal(‘pop’) we should get TRUE. Hint: define your function as abc_pal(str). This indicates that string will be passed. Next create two empty lists L1=[] and L2=[] ....
Python please Write a function that takes a string as an argument checks whether it is...
Python please Write a function that takes a string as an argument checks whether it is a palindrome. A palindrome is a word that is the same spelt forwards or backwards. Use similar naming style e.g. name_pal. E.g. If we call the function as abc_pal(‘jason’) we should get FALSE and if we call it a abc_pal(‘pop’) we should get TRUE. Hint: define your function as abc_pal(str). This indicates that string will be passed. Next create two empty lists L1=[] and...
C programming Write a function called string in() that takes two string pointers as arguments. If...
C programming Write a function called string in() that takes two string pointers as arguments. If the second string is contained in the first string, have the function return the address at which the contained string begins. For instance, string in(“hats”, “at”) would return the address of the a in hats. Otherwise, have the function return the null pointer. Test the function in a complete program that uses a loop to provide input values for feeding to the function.
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
PYTHON Basic Feature[5pts] Write a function which takes two arguments—a string (str1) and a position index...
PYTHON Basic Feature[5pts] Write a function which takes two arguments—a string (str1) and a position index (n). The function will: 1.Remove the n-th characterof str1 (the initial character is the 0-th character) 2.Swap the order of the substring in front of the removed character and the substring afterwards, and concatenate them as a new string 3.Return the converted (str2) back to the function caller For example, myfunc(“abc1xyz”, 3) returns “xyzabc”. Additional Features [6 pts] Expand the function by adding more...
6. Write a Python function that checks whether a passed string is palindrome or not. Note:-A...
6. Write a Python function that checks whether a passed string is palindrome or not. Note:-A palindrome is a word, phrase, or sequence that reads the same backward as forward . Some examples you may try: “madam” redder “race car” Eva, Can I Stab Bats In A Cave? If the argument passed is not a string, invoke an exception or an assertion and state in a comment which one you have chosen and why.
. Write   a   function   that   takes,   as   arguments,   two   objects,   value1   and   value2.       If  
. Write   a   function   that   takes,   as   arguments,   two   objects,   value1   and   value2.       If   value1   and   value2   are   either   integers   or   strings   containing   only   digits,   cast   value1   and   value2   to   integers   and   compute   their   average.       If   their   average   is   greater   than   50,   return   the   string   “Above   50”   and   if   the   average   is   less   than   50,   return   the   string   “Below   50”.       If   the   average   is   equal   to   50,   return   the   string   “Equal   to   50”,   and   if   value1   or  ...
Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The...
Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The function will check each character of the strings in the array and removes the character, regardless of case. If the first letter of the string is removed the next letter must be capitalized. Your function would return the result as one string, where each element of array is separated by comma. E.G. function([“John”,”Hannah”,”Saham”], “h”); // returns ‘Jon,Anna,Saam Use of any built in string function...
JavaScript Write a function called "first" that takes in two arguments - the first is an...
JavaScript Write a function called "first" that takes in two arguments - the first is an argument called arr that is an array of numbers, the second is an optional number argument called num(hint: you'll need a default value - look back at the slides). If "num" was not passed in (since it's optional), the "first" function will return an array containing the first item of the array. If a value for "num" was given, the "first" function will return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT