Hello, can someone help me to rank numbers. Example: input: a = [35, 26, 65, 15], output: [2nd, 3rd, 1st, 4th]. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hello, can someone help me to rank numbers. Example: input: a = [35, 26, 65, 15], output: [2nd, 3rd, 1st, 4th].

Ordinal Ranking in Python

2nd Mar 2020, 3:52 PM
Osei Kwadwo
2 Answers
0
this might help.. Make a list of your ranking e.g... rankValues = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th'...etc.. Make a dict using zip.... use "sorted" (not the in-place sort) and "reversed" for your list of numbers...use the rankValues in your zip too.. Do a list comprehension using the dict and the list of numbers using a " for...in". (lol...it would be quicker if I just posted the actual code wouldn't it...but.... it's frowned upon)
2nd Mar 2020, 9:11 PM
rodwynnejones
rodwynnejones - avatar