Walk a list and keep only the values that meet a condition — here, readings at or above a threshold. The trace shows kept growing with each qualifying element and staying flat when a value is rejected.

By hand

Initialise an empty kept list. Inside the loop an if guards the append: kept only grows when v >= threshold.

naive.py
Replay: real traced execution (multi-file project)
values = [3, 7, 1, 9, 4, 8, 2, 6]
threshold = 5
kept = []
for v in values:
    if v >= threshold:
        kept.append(v)
print('RESULT:', kept)
  1. values ← [3, 7, 1, 9, 4, 8, 2, 6]

    1values = [3, 7, 1, 9, 4, 8, 2, 6]2threshold = 5
    values this step[3, 7, 1, 9, 4, 8, 2, 6]values
  2. threshold ← 5

    1values = [3, 7, 1, 9, 4, 8, 2, 6]2threshold = 53kept = []
    values this step5threshold
  3. kept ← []

    2threshold = 53kept = []4for v in values:
    values this step[]kept
  4. v ← 3

    3kept = []4for v in values:5    if v >= threshold:
    values this step3v
  5. if v >= threshold:

    4for v in values:5    if v >= threshold:6        kept.append(v)
  6. v ← 7

    3kept = []4for v in values:5    if v >= threshold:
    values this step3 7v
  7. if v >= threshold:

    4for v in values:5    if v >= threshold:6        kept.append(v)
  8. kept ← [7]

    5    if v >= threshold:6        kept.append(v)7print('RESULT:', kept)
    values this step[] [7]kept
  9. v ← 1

    3kept = []4for v in values:5    if v >= threshold:
    values this step7 1v
  10. if v >= threshold:

    4for v in values:5    if v >= threshold:6        kept.append(v)
  11. v ← 9

    3kept = []4for v in values:5    if v >= threshold:
    values this step1 9v
  12. if v >= threshold:

    4for v in values:5    if v >= threshold:6        kept.append(v)
  13. kept ← [7, 9]

    5    if v >= threshold:6        kept.append(v)7print('RESULT:', kept)
    values this step[7] [7, 9]kept
  14. v ← 4

    3kept = []4for v in values:5    if v >= threshold:
    values this step9 4v
  15. if v >= threshold:

    4for v in values:5    if v >= threshold:6        kept.append(v)
  16. v ← 8

    3kept = []4for v in values:5    if v >= threshold:
    values this step4 8v
  17. if v >= threshold:

    4for v in values:5    if v >= threshold:6        kept.append(v)
  18. kept ← [7, 9, 8]

    5    if v >= threshold:6        kept.append(v)7print('RESULT:', kept)
    values this step[7, 9] [7, 9, 8]kept
  19. v ← 2

    3kept = []4for v in values:5    if v >= threshold:
    values this step8 2v
  20. if v >= threshold:

    4for v in values:5    if v >= threshold:6        kept.append(v)
  21. v ← 6

    3kept = []4for v in values:5    if v >= threshold:
    values this step2 6v
  22. if v >= threshold:

    4for v in values:5    if v >= threshold:6        kept.append(v)
  23. kept ← [7, 9, 8, 6]

    5    if v >= threshold:6        kept.append(v)7print('RESULT:', kept)
    values this step[7, 9, 8] [7, 9, 8, 6]kept
  24. for v in values:

    3kept = []4for v in values:5    if v >= threshold:
  25. stdout ← RESULT: [7, 9, 8, 6]

    6        kept.append(v)7print('RESULT:', kept)
    values this stepRESULT: [7, 9, 8, 6]stdout

The Pythonic way

A list comprehension [v for v in values if v >= threshold] expresses the same filter in one line, without an explicit accumulator or append call.

library.py
values = [3, 7, 1, 9, 4, 8, 2, 6]
threshold = 5
kept = [v for v in values if v >= threshold]
print('RESULT:', kept)
RESULT: [7, 9, 8, 6]

Implementation notes

  • kept grows visibly in the trace: [][7][7, 9][7, 9, 8][7, 9, 8, 6]; the four rejected values produce zero-delta events.
  • Every if v >= threshold: event is zero-delta (condition evaluation changes no variables); the kept.append(v) event that follows marks a passing value.
  • The list comprehension runs its own internal loop, so v does not appear as a traced variable in the library half.