Keep only the largest k values
Sorting every value is unnecessary when the answer contains only a few winners. A small min-heap keeps the largest k values seen so far; its smallest value is the easiest winner to replace. Python's heapq.nlargest implements this selection for any iterable. Duplicates still count as separate observations unless the task says otherwise.
import heapq
print(heapq.nlargest(2, iter([3, 9, 1, 7])))Think before coding
A bounded heap avoids retaining and sorting the whole source when k is small. nlargest also accepts iterators directly, and its descending output is part of the public contract. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write largest_values(values, k), returning up to k largest numbers in descending order, preserving duplicates. Accept a one-pass iterable. Return [] when k <= 0.
The explanation opens here once every check passes.