# mingle -- mingle elements of several lists

## Synopsis

• Usage:
mingle(L)
• Inputs:
• L, , a list of lists L=\{L1, L2, ..., Ln\}
• Outputs:
• M, a list, a new list mingling the elements of all lists in L

## Description

The output list M takes the first element of each Li, i=1,...,n, followed by the second element of Li, i=1,...,n, and so forth.

 i1 : mingle {{a1, a2, a3}, {b1, b2, b3}, {c1, c2, c3}} o1 = {a1, b1, c1, a2, b2, c2, a3, b3, c3} o1 : List

The lists can have different lengths. After a list is exhausted, it will be silently ignored.

 i2 : mingle {{a1, a2, a3, a4}, {b1, b2}, {c1}} o2 = {a1, b1, c1, a2, b2, a3, a4} o2 : List

To transpose a nested list (thinking of it as a matrix), try using mingle with pack.

 i3 : pack(3, mingle ((a1, a2, a3), (b1, b2, b3), (c1, c2, c3))) o3 = {{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}} o3 : List

Notice from the previous example that mingle accepts sequences and other types of BasicLists as input, but the output will always be a List.

Further examples:

 i4 : concatenate mingle( {"a","b","c"} , {",",","} ) o4 = a,b,c i5 : netList pack(3, mingle( (0..5), apply(6, i -> i^2), apply(6, i -> i^3))) +-+--+---+ o5 = |0|0 |0 | +-+--+---+ |1|1 |1 | +-+--+---+ |2|4 |8 | +-+--+---+ |3|9 |27 | +-+--+---+ |4|16|64 | +-+--+---+ |5|25|125| +-+--+---+

• apply -- apply a function to each element
• insert -- copy a list, inserting an element
• join -- join lists and sequences
• pack -- pack elements of a list into several shorter lists
• sort -- sort a list or columns of a matrix
• sublists -- process interspersed subsequences of a visible list
• lists and sequences -- a detailed overview of lists and sequences in Macaulay2

## Ways to use mingle :

• "mingle(BasicList)"

## For the programmer

The object mingle is .