Skip to main content

Practice ยท 2 of 2

Finite Cycler

Create a class Cycler(items) that loops over a finite list forever when used with next() directly, BUT supports it = iter(c) producing an iterator that cycles. Implement it as an iterator whose __next__ wraps around using modulo.

Difficulty: intermediate

Back to lesson: Practice: Iterator Drills