Custom Range
mediumpy_classesImplement a Range class (plus its RangeIterator) that mimics the built-in
range: an immutable arithmetic sequence.
Range(stop), Range(start, stop), or Range(start, stop, step) — start
defaults to 0, step to 1, and step == 0 raises ValueError. Support
iteration (re-iterable), len, indexing with negative indices (IndexError
when out of range), membership (in) in O(1), and a range-style repr
(str(Range(10)) == "range(0, 10)").
Your solution
Edit Range and run the real pytest suite in your browser — no install required. Your code is saved locally.
Loading the Python runtime (first run only)…
Hints
Hint 1
Store start/stop/step and precompute the length; __getitem__ returns start + index*step (map negative indices via len + index).
Hint 2
Make __contains__ O(1) arithmetic (in-bounds and (key-start) % step == 0); return a fresh iterator from __iter__ so it's re-iterable.