Pybites Logo Rust Platform

Iterator Basics

Easy +2 pts

🎯 In Python, iteration is simple — for x in collection works on anything iterable, and you never think about whether you're borrowing or consuming the data:

nums = [1, 2, 3]
for x in nums:
    print(x)
# nums is still here — Python uses reference counting

You can also mutate in place:

nums[0] = 99  # direct index assignment

Rust has the same for x in collection syntax, but because there's no garbage collector, you need to choose how you access each element — borrow it, mutate it, or take ownership of it.

Three iterator methods — matching the ownership model

This …

Login to see the full exercise.