Pybites Logo Rust Platform

Collecting Into Different Types

Medium +3 pts

🎯 In Python, converting between collection types is effortless:

numbers = [3, 1, 2, 1, 3] unique = set(numbers) # {1, 2, 3} sorted_list = sorted(unique) # [1, 2, 3] pairs = [("a", 1), ("b", 2)] lookup = dict(pairs) # {"a": 1, "b": 2} from collections import Counter Counter(["red", "blue", "red"]) # {'red': 2, 'blue': 1}

You call set(), dict(), list(), sorted() — the constructor does the work. In Rust, one method does all of …

Login to see the full exercise.