## `zip` -- combine lists

#### Introduction

`zip``(list1, list2, f)` combines two lists via a function `f`. It returns a list whose i-th entry is `f(list1[i], list2[i])`. Its length is the minimum of the lengths of the two input lists.

`zip``(list1, list2, f, default)` returns a list whose length is the maximum of the lengths of the two input lists. The shorter list is padded with the `default` value.

#### Call(s)

`zip(list1, list2, f)`
`zip(list1, list2, f, default)`

#### Parameters

`list1, list2` | - | lists of arbitrary MuPAD objects
`f` | - | any MuPAD object. Typically, a function of two arguments.
`default` | - | any MuPAD object

#### Returns

a list.

### Overloadable:

`list1`, `list2`

#### Related Functions

`map`, `op`, `select`, `split`

#### Details

- If `f` produces the void object of type `DOM_NULL`, then this element is removed from the resulting list.
- `zip` is recommended for fast manipulation of lists. It is a function of the system kernel.

#### Example 1

The fastest way of adding the entries of two lists is to 'zip' them via the function `_plus`:

    >> zip([a, b, c, d], [1, 2, 3, 4], _plus)

                           [a + 1, b + 2, c + 3, d + 4]

If the input lists have different lengths, then the shorter list determines the length of the returned list:

    >> zip([a, b, c, d], [1, 2], _plus)

                                  [a + 1, b + 2]

The longer list determines the length of the returned list if a value for padding the shorter list is provided:

    >> zip([a, b, c, d], [1, 2], _plus, 17)

                          [a + 1, b + 2, c + 17, d + 17]

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000