PythiloLesson 7 of 8 · progress kept in this browser

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])
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.