ZIP of two lists into a single list of pairs (subroutine)

Subroutine and a test example:
ZIP of two lists into a single list of pairs

For example,

combining:
100,200,300,400,500,600

with
alpha,beta,gamma,delta,epsilon

to form

100	alpha
200	beta
300	gamma
400	delta
500	epsilon
600

by specifying:

  1. The input list delimiter (default, if omitted: ",")
  2. the string which will separate the two items of each output pair (default, if omitted: ",")
  3. the output list delimiter (default, if omitted: "\n")

(Note that this is a 'long' zip – where two input lists differ in length, each lonely item at the end is paired with an empty string)


test Macros.kmmacros (7.4 KB)

3 Likes

On the same theme, here's a subroutine I came up with for combining per-line lists with optional prefix, divider and suffix.

List 1:

123
456
789

List 2:

ABC
DEF
GHI

Prefix: Beginning:
Divider: - Middle:
Suffix: - End

Result:

Beginning: 123 - Middle: ABC - End
Beginning: 456 - Middle: DEF - End
Beginning: 789 - Middle: GHI - End

Combine Two Lists as Columns (Subroutine).kmmacros (21 KB)

Macro screenshot

Combine Two Lists as Columns (Example Caller).kmmacros (22 KB)

Macro screenshot

3 Likes