Logo

Programming-Idioms

Generate a "zipped" list z of pairs of elements from the lists a, b having the same length n.

The result z will contain n pairs.
New implementation

Type ahead, or select one

Explain stuff

To emphasize a name: _x → x

Please be fair if you are using someone's work

You agree to publish under the CC-BY-SA License

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import static java.util.Arrays.stream;
Object[] zip(Object[] ... c) {
    Object[] t, T;
    int a, b, i, m = c.length,
        z = stream(c).mapToInt(x -> x.length)
                     .max().getAsInt();
    t = new Object[z];
    for (b = i = 0; b < z; ++b) {
        T = new Object[m];
        for (a = 0; a < m; ++a)
            if (b < c[a].length)
                T[a] = c[a][b];
        t[i++] = T;
    }
    return t;
}

Order is preserved; all values are returned.