I have the following list of list:
[['3', 2], ['2370447', 282], ['5300058', 610], ['81615', 615], ['3294332', 624], ['3078798', 624], ['1804986', 643]]
Please note that in index 5 and 6, the second item is identical. I am trying to turn this list ordered on the second item in each list into a ranking.
I used the following if-else to correct for time when values were the same:
for i in range(len(sortedCounts)):
if i == 0:
sortedCounts[i][1] = 0
elif sortedCounts[i][1] == sortedCounts[i-1][1]:
sortedCounts[i][1] = i-1
else:
sortedCounts[i][1] = i
However, when I print the list, I am still getting different rankings even when the numbers are the same:
[['3', 0], ['2370447', 1], ['5300058', 2], ['81615', 3], ['3294332', 4], ['3078798', 5], ['1804986', 6]]
Expected output is: [['3', 0], ['2370447', 1], ['5300058', 2], ['81615', 3], ['3294332', 4], ['3078798', 4], ['1804986', 6]]
Appreciate any advice, or if there is a better way, please advise.
Aucun commentaire:
Enregistrer un commentaire