Understanding Rank vs. Index in Sorted Python Lists
In a sorted list, the 'rank' of an element is its position when the list is sorted in ascending order. The first element in the sorted list has a rank of 1, the second element has a rank of 2, and so on.
The 'index' of an element in the sorted list refers to its position in the original, unsorted list. For example, if the original list was [4, 2, 7, 1, 3] and the sorted list is [1, 2, 3, 4, 7], the index of the element 4 in the sorted list is 4, as it was the fourth element in the original list.
Therefore, the rank and index of an element in a sorted list are distinct but connected through the sorting process.
原文地址: https://www.cveoy.top/t/topic/lfha 著作权归作者所有。请勿转载和采集!