getitem

iteration_utilities.getitem(iterable, idx=None, start=None, stop=None, step=None)

Get the item at idx or the items specified by start, stop and step.

Parameters:

iterable : iterable

The iterable from which to extract the items.

idx : positive int, -1, tuple/list thereof, or None, optional

If not None, get the item at idx. If it’s a tuple or list get all the items specified in the tuple (they will be sorted so the specified indices are retrieved). Default is None.

Note

This parameter must not be None if also start, stop and step are None.

start : int or None, optional

If None then take all items before stop, otherwise take only the items starting by start. Default is None.

Note

This parameter is ignored if idx is not None.

stop : int or None, optional

If None then take all items starting by start, otherwise only take the items before stop. Default is None.

Note

This parameter is ignored if idx is not None.

step : positive int or None, optional

If None then take all items seperated by step, otherwise take successive items. Default is None.

Note

This parameter is ignored if idx is not None.

Returns:

items : any type or generator

If idx was not None then it returns the item, otherwise it returns the items specified by start, stop and step.

Examples

The main bulk of examples is in getitem() because that’s where this function was originally implemented.