Identify which positions in a list of sensor readings are missing (None) and count how many are absent. The trace shows flags growing one boolean at a time and count incrementing only on missing values.

By hand

Iterate over values. For each element test v is None to get a boolean, append it to flags, and increment count when the test is True.

naive.py
Replay: real traced execution (multi-file project)
values = [3.1, None, 7.2, None, 5.0, None, 8.4, 2.9]
flags = []
count = 0
for v in values:
    missing = v is None
    flags.append(missing)
    if missing:
        count = count + 1
print('RESULT:', (count, flags))
  1. values ← [3.1, None, 7.2, None, 5.0, None, 8.4, 2.9]

    1values = [3.1, None, 7.2, None, 5.0, None, 8.4, 2.9]2flags = []
    values this step[3.1, None, 7.2, None, 5.0, None, 8.4, 2.9]values
  2. flags ← []

    1values = [3.1, None, 7.2, None, 5.0, None, 8.4, 2.9]2flags = []3count = 0
    values this step[]flags
  3. count ← 0

    2flags = []3count = 04for v in values:
    values this step0count
  4. v ← None, missing ← True, flags ← [False, True], count ← 1

    pass 1 of 3
    3count = 04for v in values:5    missing = v is None6    flags.append(missing)7    if missing:8        count = count + 19print('RESULT:', (count, flags))
    values this step3.1 NonevFalse Truemissing[False] [False, True]flags0 1count
    All 3 passes — pass 1 is the card above
    passvmissingflagscount
    13.1 NoneFalse True[False] [False, True]0 1
    27.2 NoneFalse True[False, True, False] [False, True, False, True]1 2
    35.0 NoneFalse True[False, True, False, True, False] [False, True, False, True, False, True]2 3
  5. v ← 8.4, missing ← False, flags ← [False, True, False, True, False, True, False]

    pass 1 of 2
    3count = 04for v in values:5    missing = v is None6    flags.append(missing)7    if missing:8        count = count + 1
    values this stepNone 8.4vTrue Falsemissing[False, True, False, True, False, True] [False, True, False, True, False, True, False]flags
  6. v ← 2.9, flags ← [False, True, False, True, False, True, False, False]

    pass 2 of 2
    3count = 04for v in values:5    missing = v is None6    flags.append(missing)7    if missing:8        count = count + 1
    values this step8.4 2.9v[False, True, False, True, False, True, False] [False, True, False, True, False, True, False, False]flags
  7. for v in values:

    3count = 04for v in values:5    missing = v is None
  8. stdout ← RESULT: (3, [False, True, False, True, False, True, False, False])

    8        count = count + 19print('RESULT:', (count, flags))
    values this stepRESULT: (3, [False, True, False, True, False, True, False, False])stdout

With pandas

Load the values into a pd.Series. isna() returns a boolean Series marking each missing position; .tolist() converts it to a plain list and .sum() counts the True entries.

library.py
import pandas as pd
from dalib.display import set_display
set_display()

values = [3.1, None, 7.2, None, 5.0, None, 8.4, 2.9]
s = pd.Series(values, dtype=float)
flags = s.isna().tolist()
count = int(s.isna().sum())
print('index:', s.index.tolist())
print('dtype:', s.dtype)
print('values:', s.tolist())
print('RESULT:', (count, flags))
index: [0, 1, 2, 3, 4, 5, 6, 7]
dtype: float64
values: [3.1, nan, 7.2, nan, 5.0, nan, 8.4, 2.9]
RESULT: (3, [False, True, False, True, False, True, False, False])

Implementation notes

  • v is None is preferred over v == None because == can be overridden by custom __eq__; is tests object identity and is always safe for None checks.
  • pd.Series(values, dtype=float) makes the numeric dtype explicit. pandas already infers float64 (replacing None with NaN) for a numeric list like this one, so the dtype=float argument is defensive rather than corrective — it documents intent and guards against edge cases where inference might choose object (e.g. a list containing mixed types).
  • int(s.isna().sum()) casts the NumPy scalar to a plain Python int so the RESULT tuple round-trips through ast.literal_eval unchanged.