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:
- iterableiterable
The iterable from which to extract the items.
- idxpositive
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 isNone
.Note
This parameter must not be
None
if also start, stop and step areNone
.- start
int
or None, optional If
None
then take all items before stop, otherwise take only the items starting by start. Default isNone
.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 isNone
.Note
This parameter is ignored if idx is not
None
.- steppositive
int
or None, optional If
None
then take all items separated by step, otherwise take successive items. Default isNone
.Note
This parameter is ignored if idx is not
None
.
- Returns:
- itemsany 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.