Rank if same value in Python list

Asked 2 years ago, Updated 2 years ago, 17 views

When Bb=[50,20,20,10,30] the output is rank=[1,2,3,3,4,5] how do I get this output? sort and reverse are written in order, but I don't know after that

python

2022-09-22 18:53

1 Answers

rank = [1, 2, 3, 4, 5] I don't understand what you want to express. If you want to express Bb like 50: 1st, 20: 2nd... You have to add the ranking by turning the for statement on the list.

Bb=[50,20,20,10,30]
Bb.sort(reverse=True)
dic = {}
for i in range(0,5):
    dic [Bb[i] = str(i+1)+'etc'
print(dic)


2022-09-22 18:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.