Try a SortedList
from the sortedcontainers
module ("written in pure-Python, and fast as C-extensions").
At the core of Sorted Containers is the mutable sequence data type SortedList. The SortedList maintains its values in ascending sort order. As with Python’s built-in list data type, SortedList supports duplicate elements and fast random-access indexing.
Values may be added to a SortedList using either SortedList.update() or SortedList.add(). When doing so, the list remains sorted.
Because SortedList is sorted, it supports efficient lookups by value or by index.
Install the module if you don't have it:
$ pip install sortedcontainers
Store your values and strings as tuple pairs:
from sortedcontainers import SortedList
sorted_list = SortedList()
# Sample data.
sorted_list.update([
(1, 'test'),
(1000, 'big number'),
(500, 'middle')])
>>> sorted_list[-1]
(1000, 'big number')
sorted_list.add((5000, 'even bigger'))
sorted_list.add((4000, 'big, but not biggest'))
# Get last two largest values.
>>> sorted_list[-2:]
[(4000, 'big, but not biggest'), (5000, 'even bigger')]