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
Replay: real traced execution (multi-file project)
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)
  1. names ← ['eve', 'bob', 'dan', 'amy', 'cal', 'fay']

    1names = ['eve', 'bob', 'dan', 'amy', 'cal', 'fay']2scores = [72, 45, 88, 31, 63, 57]
    values this step['eve', 'bob', 'dan', 'amy', 'cal', 'fay']names
  2. scores ← [72, 45, 88, 31, 63, 57]

    1names = ['eve', 'bob', 'dan', 'amy', 'cal', 'fay']2scores = [72, 45, 88, 31, 63, 57]3remain = list(range(len(names)))
    values this step[72, 45, 88, 31, 63, 57]scores
  3. remain ← [0, 1, 2, 3, 4, 5]

    2scores = [72, 45, 88, 31, 63, 57]3remain = list(range(len(names)))4result = []
    values this step[0, 1, 2, 3, 4, 5]remain
  4. result ← []

    3remain = list(range(len(names)))4result = []5while remain:
    values this step[]result
  5. while remain:

    4result = []5while remain:6    best = min(remain, key=lambda i: scores[i])
  6. best ← 3

    5while remain:6    best = min(remain, key=lambda i: scores[i])7    result.append(names[best])
    values this step3best
  7. result ← ['amy']

    6best = min(remain, key=lambda i: scores[i])7result.append(names[best])8remain.remove(best)
    values this step[] ['amy']result
  8. remain ← [0, 1, 2, 4, 5]

    7    result.append(names[best])8    remain.remove(best)9print('RESULT:', result)
    values this step[0, 1, 2, 3, 4, 5] [0, 1, 2, 4, 5]remain
  9. while remain:

    4result = []5while remain:6    best = min(remain, key=lambda i: scores[i])
  10. best ← 1

    5while remain:6    best = min(remain, key=lambda i: scores[i])7    result.append(names[best])
    values this step3 1best
  11. result ← ['amy', 'bob']

    6best = min(remain, key=lambda i: scores[i])7result.append(names[best])8remain.remove(best)
    values this step['amy'] ['amy', 'bob']result
  12. remain ← [0, 2, 4, 5]

    7    result.append(names[best])8    remain.remove(best)9print('RESULT:', result)
    values this step[0, 1, 2, 4, 5] [0, 2, 4, 5]remain
  13. while remain:

    4result = []5while remain:6    best = min(remain, key=lambda i: scores[i])
  14. best ← 5

    5while remain:6    best = min(remain, key=lambda i: scores[i])7    result.append(names[best])
    values this step1 5best
  15. result ← ['amy', 'bob', 'fay']

    6best = min(remain, key=lambda i: scores[i])7result.append(names[best])8remain.remove(best)
    values this step['amy', 'bob'] ['amy', 'bob', 'fay']result
  16. remain ← [0, 2, 4]

    7    result.append(names[best])8    remain.remove(best)9print('RESULT:', result)
    values this step[0, 2, 4, 5] [0, 2, 4]remain
  17. while remain:

    4result = []5while remain:6    best = min(remain, key=lambda i: scores[i])
  18. best ← 4

    5while remain:6    best = min(remain, key=lambda i: scores[i])7    result.append(names[best])
    values this step5 4best
  19. result ← ['amy', 'bob', 'fay', 'cal']

    6best = min(remain, key=lambda i: scores[i])7result.append(names[best])8remain.remove(best)
    values this step['amy', 'bob', 'fay'] ['amy', 'bob', 'fay', 'cal']result
  20. remain ← [0, 2]

    7    result.append(names[best])8    remain.remove(best)9print('RESULT:', result)
    values this step[0, 2, 4] [0, 2]remain
  21. while remain:

    4result = []5while remain:6    best = min(remain, key=lambda i: scores[i])
  22. best ← 0

    5while remain:6    best = min(remain, key=lambda i: scores[i])7    result.append(names[best])
    values this step4 0best
  23. result ← ['amy', 'bob', 'fay', 'cal', 'eve']

    6best = min(remain, key=lambda i: scores[i])7result.append(names[best])8remain.remove(best)
    values this step['amy', 'bob', 'fay', 'cal'] ['amy', 'bob', 'fay', 'cal', 'eve']result
  24. remain ← [2]

    7    result.append(names[best])8    remain.remove(best)9print('RESULT:', result)
    values this step[0, 2] [2]remain
  25. while remain:

    4result = []5while remain:6    best = min(remain, key=lambda i: scores[i])
  26. best ← 2

    5while remain:6    best = min(remain, key=lambda i: scores[i])7    result.append(names[best])
    values this step0 2best
  27. result ← ['amy', 'bob', 'fay', 'cal', 'eve', 'dan']

    6best = min(remain, key=lambda i: scores[i])7result.append(names[best])8remain.remove(best)
    values this step['amy', 'bob', 'fay', 'cal', 'eve'] ['amy', 'bob', 'fay', 'cal', 'eve', 'dan']result
  28. remain ← []

    7    result.append(names[best])8    remain.remove(best)9print('RESULT:', result)
    values this step[2] []remain
  29. while remain:

    4result = []5while remain:6    best = min(remain, key=lambda i: scores[i])
  30. stdout ← RESULT: ['amy', 'bob', 'fay', 'cal', 'eve', 'dan']

    8    remain.remove(best)9print('RESULT:', result)
    values this stepRESULT: ['amy', 'bob', 'fay', 'cal', 'eve', 'dan']stdout

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.