Pybites Logo Rust Platform

Map and Filter

Easy +2 pts

🎯 In Python, list comprehensions handle both transforming and filtering in one readable expression:

squares = [x**2 for x in numbers] evens = [x for x in numbers if x % 2 == 0] lengths = [len(s) for s in words if s]

Python also has map() and filter() builtins, but list comprehensions are more idiomatic. In Rust, iterator methods like .map() and .filter() are the idiomatic approach — they replace both loops and comprehensions.

.map()

Login to see the full exercise.