Build disjoint evaluation folds
Cross-validation assigns each observation to a held-out fold while using the remaining observations for training. The key correctness rule is separation: no test index may appear in training for the same fold. A deterministic round-robin assignment makes the mechanics visible without relying on a random shuffle. Real datasets may require grouped or time-aware splits instead.
indices = list(range(6))
print(indices[0::3])
print(indices[1::3])Think before coding
Every index has exactly one remainder, so it is held out exactly once. Training excludes the matching remainder. Preprocessing and model selection must still be fitted separately within each training fold. 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 folds(n, k), with n >= k >= 2. Return k pairs (train_indices, test_indices). Fold f holds out indices i where i % k == f. Lists must be ascending. Raise ValueError for invalid n or k.
The explanation opens here once every check passes.