Question

In: Computer Science

Complete the isScrambled() function to return True if stringA can be reordered to make stringB. Otherwise,...

Complete the isScrambled() function to return True if stringA can be reordered to make stringB. Otherwise, return False. Ignore spaces and capitalization. You must use a list for this assignment. isScrambled( 'Easy', 'Yase' ) returns True isScrambled( 'Easy', 'EasyEasy' ) returns False isScrambled( 'eye', 'eyes' ) returns False isScrambled( 'abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba' ) returns True isScrambled( 'Game Test', 'tamegest' ) returns True.

Solutions

Expert Solution

def isScrambled(stringA, stringB):
    stringA = stringA.lower() # make all the letters to lower case
    stringA = ''.join(stringA.split()) # remove spaces from the string

    stringB = stringB.lower() # make all the letters to lower case
    stringB = ''.join(stringB.split()) # remove spaces from the string

    a_list = list(stringA) # convert string to list
    a_list.sort() # sort the list

    b_list=list(stringB)# convert string to list
    b_list.sort() # sort the list

    return a_list==b_list # compare the list and return the result as the final answer


print(isScrambled('Easy', 'Yase'))
print(isScrambled('Easy', 'EasyEasy'))
print(isScrambled('eye', 'eyes'))
print(isScrambled('abcdefghijklmnopqrstuvwxyz', 'zyxwvutsrqponmlkjihgfedcba'))
print(isScrambled('Game Test', 'tamegest'))

===================================================================


Related Solutions

Create a function that will return true if numbers X and Y exist within S such that X + Y = Z, return false otherwise.
Given:   S = [ 2, 1, 3, 4, 7, 5 ] Z = 8   Create a function that will return true if numbers X and Y exist within S such that X + Y = Z, return false otherwise.   Code in Java 8. 
public boolean isPrime(int num){ // return true if the number is prime, false otherwise } public...
public boolean isPrime(int num){ // return true if the number is prime, false otherwise } public boolean isOdd(int num){ // return true if the number is odd, false otherwise } public String reverseMyString(String input){ // using a loop, reverse a string // i.e. input = "hello", reversed answer: "olleh" // i.e. input = "bye", reversed answer: "eyb" } public int pow(int base, int power){ // using for loop, calculate base raised to power // i.e. base = 2, power =...
For each statement below circle TRUE if the statement is true, otherwise circle FALSE.
For each statement below circle TRUE if the statement is true, otherwise circle FALSE. A hypothesis test uses data from a sample to assess a claim about a population. A randomization distribution will be centered at the value used in the null hypothesis. “Failing to reject the null hypothesis” and “accepting the null hypothesis” mean the same thing in a hypothesis test’s conclusion. The p-value is the probability, assuming the alternative hypothesis is true, of obtaining a sample statistic as...
Complete this return statement so that it could be used in the function body offind_percentageto fulfill...
Complete this return statement so that it could be used in the function body offind_percentageto fulfill the requirements for the last step's program. Fill in the Blanks — Fill in the blanks return ________ /___________
Complete the function ConvertToDecadesAndYears to convert totalYears to decades and years. Return decades and years using...
Complete the function ConvertToDecadesAndYears to convert totalYears to decades and years. Return decades and years using the ElapsedDecadesYears struct. Ex: 26 years is 2 decades and 6 years. #include <iostream> using namespace std; struct ElapsedDecadesYears {    int decadesVal;    int yearsVal; }; ElapsedDecadesYears ConvertToDecadesAndYears(int totalYears) {    ElapsedDecadesYears tempVal;    /* Your code goes here */ } int main() {    ElapsedDecadesYears elapsedYears;    int totalYears;    cin >> totalYears;    elapsedYears = ConvertToDecadesAndYears(totalYears);    cout << elapsedYears.decadesVal <<...
complete in python The function sumEven should return the sum of only the even numbers contained...
complete in python The function sumEven should return the sum of only the even numbers contained in the list, lst. Example list_of_nums = [1, 5, 4, 8, 5, 3, 2] x = sum_evens(list_of_nums) print(x) #prints 14 Start your code with def evens(lst):
Write a C++ function template to add two inputs and return their result. Make exceptions for...
Write a C++ function template to add two inputs and return their result. Make exceptions for Characters (such that sum of two characters is a character associated with sum of their ASCII) and String (such that sum of two strings is their concatenation)
public int getIndexOfWord(String[] arr, String word){ // if found, return the index of word, otherwise return...
public int getIndexOfWord(String[] arr, String word){ // if found, return the index of word, otherwise return -1 } public boolean areArrays(int[] arr1, int[] arr2){ // 1. initial check: both arrays need to have the same length, return false if not the same // 2. return true if both given arrats are equals(same values in the same indices), false otherwise } public boolean areArraysEqual(String[] arr1, String[] arr2){ // 1. initial check: both arrays need to have the same length, return false...
(True or False) The following function will compile. void print(int num) { return num+1; } Group...
(True or False) The following function will compile. void print(int num) { return num+1; } Group of answer choices True False Flag this Question Question 2 10 pts (True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; } Group of answer...
Unless otherwise stated, answer in complete sentences, and be sure to use correct English spelling and...
Unless otherwise stated, answer in complete sentences, and be sure to use correct English spelling and grammar. Sources must be cited in APA format. Your response should be two (2) to four (4) pages in length; refer to the "Assignment Format" page for specific format requirements. Lesson 1, 2, 3, and 4 of this course has covered a wide variety of topics. Thus far, you have learned a great deal of information on health insurance, medical contracts, HIPAA, physician and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT