Python list comprehension is really simple:
>>> l = [x ** 2 for x in range(10) if x % 2 == 0]
>>> [0, 4, 16, 36, 64]
Does Rust have an equivalent syntax like:
let vector = vec![x for x in (1..10) if x % 2 == 0]
// [2, 4, 6, 8]
Python list comprehension is really simple:
>>> l = [x ** 2 for x in range(10) if x % 2 == 0]
>>> [0, 4, 16, 36, 64]
Does Rust have an equivalent syntax like:
let vector = vec![x for x in (1..10) if x % 2 == 0]
// [2, 4, 6, 8]
cute is a macro for Python-esque list and dictionary (
HashMap
) comprehensions in Rust.You can just use iterators: