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 with elem`

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]
arsenal.collections.index_collated_dict(d: Dict[str, Any], idxs: Sequence[int]) → Dict[str, Any][source]
Parameters
  • d – dictionary of sequences with arbitrary levels of sub-dictionary nesting

  • idxs – list/array of indices

Returns

Dictionary where all sequences are indexed by idxs.