ensure_iterable

lsst.utils.iteration.ensure_iterable(a: Any) Iterable[Any]

Ensure that the input is iterable.

There are multiple cases, when the input is:

  • iterable, but not a str or Mapping -> iterate over elements (e.g. [i for i in a])

  • a str -> return single element iterable (e.g. [a])

  • a Mapping -> return single element iterable

  • not iterable -> return single element iterable (e.g. [a]).

Parameters:
aiterable or str or not iterable

Argument to be converted to an iterable.

Returns:
igenerator

Iterable version of the input value.