interleave

maelzel.distribute.interleave(A, B, weight=0.5)[source]

interleave the elements of A and B

Parameters:
  • A (list[TypeVar(T)]) – a list of elements

  • B (list[TypeVar(T)]) – another list of elements

  • weight – Between 0-1. 0: first the elements of xs, then B, not interleaved; 0.5: interleave A and B regularly; 1: first the elements of B, then A

Return type:

list[TypeVar(T)]

Returns:

a list with items of A and B interleaved

Example

>>> from maelzel import distribute
>>> A = ["A", "B", "C"]
>>> B = ["a", "b", "c", "d", "e"]
>>> "".join(distribute.interleave(A, B))
'aAbcBdCe'