In: Computer Science
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.
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'))
===================================================================