Order a list of names by a paired numeric score using a repeated selection-of-minimum. Each step picks the index of the lowest remaining score, appends the corresponding name to the result, then removes that index so it cannot be chosen again.

By hand

remain starts as [0, 1, 2, 3, 4, 5] — the full set of available indices. Each iteration calls min(remain, key=lambda i: scores[i]) to find which remaining index has the lowest score, appends names[best] to result, then removes best from remain. When remain is empty the loop exits.

naive.py
names = ['eve', 'bob', 'dan', 'amy', 'cal', 'fay']
scores = [72, 45, 88, 31, 63, 57]
remain = list(range(len(names)))
result = []
while remain:
    best = min(remain, key=lambda i: scores[i])
    result.append(names[best])
    remain.remove(best)
print('RESULT:', result)

The Pythonic way

zip(names, scores) pairs each name with its score; sorted(..., key=lambda x: x[1]) orders by the score field; the comprehension strips the score back out, leaving the sorted names.

library.py
names = ['eve', 'bob', 'dan', 'amy', 'cal', 'fay']
scores = [72, 45, 88, 31, 63, 57]
result = [n for n, s in sorted(zip(names, scores), key=lambda x: x[1])]
print('RESULT:', result)
RESULT: ['amy', 'bob', 'fay', 'cal', 'eve', 'dan']

Implementation notes

  • Data is stored in parallel lists because a list of record dicts would exceed the 80-character repr limit after two elements; tuple is also not in the tracer's tracked types, so index integers are used instead.
  • remain shrinks by one per step and result grows by one — both are visible in the trace. The while remain: condition events are zero-delta (condition evaluation changes no variables).
  • The selection-of-minimum approach makes O(n²) comparisons; sorted uses Timsort at O(n log n). For six elements the difference is negligible.