Question: PYTHON LANGUAGE PLEASE 3 compare_front(), compare_back() The functions compare_front () and compare_back() will each take two pa- rameters, both of which are linear types (strings,

PYTHON LANGUAGE PLEASE
3 compare_front(), compare_back() The functions compare_front () and compare_back() will each take two pa- rameters, both of which are linear types (strings, lists, or tuples). Each function uld compare the type of the two parameters, and assert that the types are the same. Do not make any assumptions about the type of data which might be stored in these elements. (In fact, it's OK for the two containers to contain different data types - so long as the type of the container is the same.) These functions will iterate through the elements of their parameters; they will see how many of the elements of the parameters are the same. compare_front() will compare from the front (starting at index 0), and compare_back() will com- pare from the rear (starting at the highest index). Each function returns the number of elements that were the same all in a row. (Once you find any difference at all, stop searching, don't look for additional matches.) Make sure to handle all of the corner cases: If the very first element you compare is different, then return 0. If the containers are different lengths, but the shorter one entirely matches the start/end of the longer one, then return the length of the shorter one. If the containers are identical in all elements, then return their length. If either of the inputs are empty, then return 0. 3.1 Examples compare_front("asdf", "ackbar") should return 1. compare_back([10,12,13], (100,200)) should fail an assert. compare_back([10,-1,0,127,12,13], ["asdf", 12, 13]) should return 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
