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 =...
The signature of each function is provided below, do not make any changes to them otherwise...
The signature of each function is provided below, do not make any changes to them otherwise the tester will not work properly. The following are the functions you must implement: mashup(lst) [20pts] Description: Creates a new string that is based on the provided list. Each number in the list specifies how many characters from the string that follows belong in the resulting string. Parameters: lst is a list of variable size, that contains alternating ints and strings Assumptions: When a...
In Python Complete the function powersOf5(). Have the function take a parameter n and return a...
In Python Complete the function powersOf5(). Have the function take a parameter n and return a list of the first n powers of 5. One way to calculate powers of 5 is by starting with 1 and then multiplying the previous number by 5. Examples: powersOf5( 1 ) returns [1] powersOf5( 2 ) returns [1, 5] powersOf5( 3 ) returns [1, 5, 25] powersOf5( 6 ) returns [1, 5, 25, 125, 625, 3125] powersOf5( 10 ) returns [1, 5, 25,...
In Python, Complete the longestWord() function to take a list as a parameter and return the...
In Python, Complete the longestWord() function to take a list as a parameter and return the length of the longest word in that list. Examples: longestWord(['Python', 'rocks']) returns 5 longestWord(['Casey', 'Riley', 'Jessie', 'Jackie', 'Jaime', 'Kerry', 'Jody']) returns 6 longestWord(['I', 'a', 'am', 'an', 'as', 'at', 'ax', 'the']) returns 3
} 1. write a function that takes a string as parameter, return true if it’s a...
} 1. write a function that takes a string as parameter, return true if it’s a valid variable name, false otherwise. You can use keyword module’s  iskeyword() to determine is a string is keyword. import keyword keyword.iskeyword(var)   #returns true or false }2. write a function that returns the length of a string (without using len() function) }3. write a function that counts number of vowels in a string }4. write a function that checks if a word is palindrome PYTHON PROGRAMMING
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 ________ /___________
The below_freezing function takes a string as its parameter and return True if the temperature specified...
The below_freezing function takes a string as its parameter and return True if the temperature specified by the string is below freezing point for water. It returns False if the temperature is at or above the freezing point. The string takes the format of a decimal number followed by a letter where F stands for Fahrenheit, C for Celsius, and K for Kelvin. For example, below_freezing("45.5F") and below_freezing("300K") both return False. below_freezing("-1.2C") and below_freezing("272K") both return True It's critical that...
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 <<...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT