arsenal.collections
¶
Module Contents¶
-
arsenal.collections.
intersperse
(ls, elem, first=False, last=False)[source]¶ - Parameters
ls – A list of elements
elem – The element to insert in between each element
first – Whether to add the element at the beginning of the sequence
last – Whether to add the element at the end of the sequence
- Returns
ls
interspersed withelem`
Examples
>>> intersperse([1, 2, 3], 0) [1, 0, 2, 0, 3] >>> intersperse([1, 2, 3], 0, first=True) [0, 1, 0, 2, 0, 3] >>> intersperse([1, 2, 3], 0, first=True, last=True) [0, 1, 0, 2, 0, 3, 0]