les_iterables.combining module

Functions for combining iterable series.

Summary

Functions:

join_with

Generate a series of items, with separators taken from a second series.

Reference

les_iterables.combining.join_with(items, separators)[source]

Generate a series of items, with separators taken from a second series.

The number of separators consumed will be one fewer than the number of items.

items[0], separators[0], items[1], separators[1], …, separators[n-2], items[n-1]

Parameters:
  • items – An iterable series of items to return.

  • separators – A series of items one of which will be returned between each item. The number of available separators must be at least one less than the number of items. Separators will only be consumed as required.

Returns:

The series of items alternating with items from separators. The first value yielded will be the first item. The last value yielded will be the last item. If items is empty an empty series will be yielded.

Raises:

ValueError – If there are too few separators to go between the supplied number of items.