R, a programming language used for Statistics and Data Analysis, has the function rank, which returns the rank for each value in a vector.
For example:
my_list = [1, 3, 3, 9, 8]
# Ranked would be: [0, 1.5, 1.5, 4, 3]
When two or more values have the same rank, they are assigned the mean of their rankings. Here, the two 3s have ranks 1 and 2, so both are assigned rank 1.5.
Implement the function rank() so that it works the same it does in R.
rank([9, 1, 4, 5, 4]) ➞ [4.0, 0.0, 1.5, 3.0, 1.5]
rank(["z", "c", "f", "b", "c"]) ➞ [4.0, 1.5, 3.0, 0.0, 1.5]