Following my question, How to iterate a Vec with indexed position in Rust, now I need to zip two dynamic vectors with their indexed position.
The enumerate
function exists for all iterators. Using zip
on two iterators a
and b
yields another iterator. Therefor you can also call enumerate
on the resulting iterator.
fn main() {
let a = vec![1; 10];
let b = vec![2; 10];
let it = a.iter().zip(b.iter());
for (i, (x, y)) in it.enumerate() {
println!("{}: ({}, {})", i, x, y);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With