Finding the k-th largest element does not need the whole list sorted. Keep a heap no bigger than k: add each element, and when the heap grows past k throw out its smallest. At the end the heap holds the k largest, and the smallest of them, heap[0], is the k-th largest.
import heapqheap = []for v in values:heapq.heappush(heap, v)if len(heap) > k:heapq.heappop(heap)return heap[0]
The second pattern: "always take the two smallest, join them, put the result back". Joining ropes at the lowest cost is like that: a rope joined early is counted again in every later join, so the short ones must be joined first. A sorted list does not help here, because the joined rope lands somewhere in the middle; a heap puts it in its place by itself.