Question

Python #Write a function called are_anagrams. The function should #have two parameters, a pair of strings....

Python

#Write a function called are_anagrams. The function should
#have two parameters, a pair of strings. The function should
#return True if the strings are anagrams of one another,
#False if they are not.
#
#Two strings are considered anagrams if they have only the
#same letters, as well as the same count of each letter. For
#this problem, you should ignore spaces and capitalization.
#
#So, for us: "Elvis" and "Lives" would be considered
#anagrams. So would "Eleven plus two" and "Twelve plus one".
#
#Note that if one string can be made only out of the letters
#of another, but with duplicates, we do NOT consider them
#anagrams. For example, "Elvis" and "Live Viles" would not
#be anagrams.


#Write your function here!

#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print: True, False, True, False, each on their own line.
print(are_anagrams("Elvis", "Lives"))
print(are_anagrams("Elvis", "Live Viles"))
print(are_anagrams("Eleven plus two", "Twelve plus one"))
print(are_anagrams("Nine minus seven", "Five minus three"))

Homework Answers

Answer #1

Python code:

#defining are_anagrams function
def are_anagrams(string1,string2):
    #converting the string to lowercase and then removing the spaces in it, then sorting the letters in it and checking if they
    #are same and returns true if they are same else False
    return(sorted(list("".join(string1.lower().split())))==sorted(list("".join(string2.lower().split()))))
#testing and printing for different testcases
print(are_anagrams("Elvis","Lives"))
print(are_anagrams("Elvis","Live Viles"))
print(are_anagrams("Eleven plus two","Twelve plus one"))
print(are_anagrams("Nine minus seven","Five minus three"))

Screenshot:


Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
#Write a function called has_a_vowel. has_a_vowel should have #one parameter, a string. It should return True...
#Write a function called has_a_vowel. has_a_vowel should have #one parameter, a string. It should return True if the string #has any vowels in it, False if it does not. def has_a_vowel(a_str): print("Starting...") for letter in a_str: print("Checking", letter) if letter in "aeiou": print(letter, "is a vowel, returning True") return True else: print(letter, "is not a vowel, returning False") return False print("Done!")       #Below are some lines of code that will test your function. #You can change the value of...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
In Python: This will require you to write several functions, and then use them in a...
In Python: This will require you to write several functions, and then use them in a program. Logical Calculator The logical calculator does math, but with logical operators. In logic, we represent a bit with 0 as false and a bit with 1 as true. The logical operators are NOT, AND and OR. Bitwise logical calculations operate on each bit of the input. The NOT operator works on just one three-bit argument. NOT 011 = 100 The AND operator works...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes...
Using python 3.5 or later, write the following program. A kidnapper kidnaps Baron Barton and writes a ransom note. It is not wrriten by hand to avoid having his hand writing being recognized, so the kid napper uses a magazine to create a ransom note. We need to find out, given the ransom note string and magazine string, is it possible to given ransom note. The kidnapper can use individual characters of words. Here is how your program should work...
Write a Python function count_bigger that takes two parameters, a nested list of objects and a...
Write a Python function count_bigger that takes two parameters, a nested list of objects and a threshold number. It returns an integer specifying how many of the objects anywhere in the nested list are numbers that are larger than the threshold. (For our purposes, "numbers" are either integers or floats.) There may be objects in the list other than numbers, in which case you would simply ignore them. Here are a couple of examples of how the function should behave...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define (h x) (sub1 (add1 x))). You will need to use...
Using nested loops, write a function called primes(a,b) that takes in two positive integers a and...
Using nested loops, write a function called primes(a,b) that takes in two positive integers a and b (where a<b). Then simply RETURNS a string containing all the prime numbers between a and b (or if there are none, the string "No Primes"). You should check that a and b are valid inputs, that is, that a and b are integers such that a<b (otherwise, the function should print “No Primes”). Three sample calls of your function (in IDLE) should produce...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • List and briefly explain each step in the ABCDE technique for examining irrational beliefs that contribute...
    asked 17 minutes ago
  • 1. Find the general solution of the first order linear differential equation: 2*x*dy/dx -y-3/sqrt(x)=0. sqrt() =...
    asked 39 minutes ago
  • Fairfield Homes is developing two parcels near Pigeon Fork, Tennessee. In order to test different advertising...
    asked 44 minutes ago
  • . For each of the following questions, say whether the random process is reasonably a binomial...
    asked 57 minutes ago
  • Please discuss why empathy is so important in light of current events. Please give specific examples
    asked 1 hour ago
  • Describe ONE thing you learned from either Peter singer or Tibor Machan author that compelled you...
    asked 1 hour ago
  • Global logistics firms such as DHL Supply Chain and Global Forwarding or C. H. Robinson Worldwide...
    asked 1 hour ago
  • Please match each factor in adoption of a new product or service to the best match...
    asked 1 hour ago
  • Fatty Acid Synthesis Assignment Explain how the activation of acetyl-CoA carboxylase prevents excess citrate in the...
    asked 1 hour ago
  • 1. Discuss and give an example of how a person might “constructively” enter a building of...
    asked 1 hour ago
  • Define the channel type for a natural trapezoidal dirt channel with a roughness of 0.045. The...
    asked 2 hours ago
  • Petroleum Production Engineering How can flow efficiency being improved without resulting into increasing water production?
    asked 2 hours ago