Question: Custom Sort in python ------------------------------------ Have been given a lot of words, all different. You are to sort them as per the following requirements: Sort


Custom Sort in python ------------------------------------ Have been given a lot of words, all different. You are to sort them as per the following requirements: Sort the words by length: the longest word first. If the length of two words is the same, compare the first letter of both the words. The letter that is lower on the lexicographical order is placed above the one that appears higher on the order. If a tie still exists, then compare the last letters. The letter that is lower on the lexicographical order is placed above the one that appears higher on the order. If a tie still exists, compare the second letters. The letter that is lower on the lexicographical order is placed above the one that appears higher on the order If a tie still exists, compare the second last letters. The letter that is lower on the lexicographical order is placed above the one that appears higher on the order And so on. Note- Lexicographical order is (A(lowest), B, C, D, … X, Y, Z(highest) ) Input: A list of words. Output: A list of the same words sorted according to the instructions in the question. Sample input [laptop, Mobile, moaile, mobize, Car] Sample output [laptop, moaile, Mobile, mobize, Car]

Step by Step Solution

3.55 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer Code def sortBas... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!