# Applying a bivariate function to the elements of two lists: zip

### 5.40.30 Applying a bivariate function to the elements of two lists: zip

The zip command applies a bivariate function to the elements of 2 lists.

- zip takes three arguments:
  - f, a function of two variables.
  - L1 and L2, two lists of the same size n.
- zip(f,L1,L2) returns a list of size n whose kth element is f applied to the kth elements of L1 and L2

#### Examples.

- Input:
  zip(’sum’,[a,b,c,d],[1,2,3,4])
  Output:

  ⎡ ⎣ | a+1,b+2,c+3,d+4 | ⎤ ⎦

- Input:
  zip((x,y)->x^2+y^2,[4,2,1],[3,5,1])
  or:

  f:=(x,y)->x^2+y^2
  zip(f,[4,2,1],[3,5,1])

  Output:

  ⎡ ⎣ | 25,29,2 | ⎤ ⎦

- Input:

  f:=(x,y)->[x^2+y^2,x+y]
  zip(f,[4,2,1],[3,5,1])

  Output:

  ⎡
  ⎢
  ⎢
  ⎣

  25 | 7
  29 | 7
  2 | 2

  ⎤
  ⎥
  ⎥
  ⎦