Question: Using Python built-in functions Problem 5 Define a function called rank(x) that satisfies the following criteria: - Returns a list giving the sample ranks of
Using Python built-in functions
Problem 5 Define a function called rank(x) that satisfies the following criteria: - Returns a list giving the sample ranks of the corresponding elements of x - That is, the first element of the output is the rank of the first element of x; the second element of the output is the rank of the second element of x; the last element of the output is the rank of the largest element of x, etc. - The rank is the ordinal index (1st, 2nd, 3rd, ...) of an element when the dataset is sorted from least to greatest - In the event of ties, the original list order should be preserved - The function should have no side-effects (i.e., it should not modify its input x ) Examples: In :rank([1,99,2,100,99]) Out: [2,4,3,5,1] In : rank([1,99,2,100,99,100]) Out: [2,4,3,5,1,6]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
