This language bar is your friend. Select your favorite languages!

Idiom #163 Print list elements by group of 2

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

for pair in list.chunks(2) {
    println!("({}, {})", pair[0], pair[1]);
import std.range;
import "fmt"
for i := 0; i+1 < len(list); i += 2 {
	fmt.Println(list[i], list[i+1])
for x in zip(list[::2], list[1::2]):
list.each_slice(2){|slice| p slice}

Do you know the best way to do this in your language ?
New implementation...

Idiom created by


Related idioms