Logo

Programming-Idioms

History of Idiom 163 > diff from v6 to v7

Edit summary for version 7 by GobbleCock:
New Rust implementation by user [GobbleCock]

Version 6

2017-11-18, 23:17:29

Version 7

2018-06-12, 09:39:08

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Code
for pair in list.chunks(2) {
    println!("({}, {})", pair[0], pair[1]);
}
Doc URL
https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.chunks
Demo URL
https://play.rust-lang.org/?gist=6da21f02bad77882524e04ce175d8d9d&version=stable&mode=debug