Skip to content

indexing

indexing

Functions:

Name Description
absindex

Ensure's Index is a positive index, -1 == length-1

absindex

absindex(index: int | None, length: int) -> int

Ensure's Index is a positive index, -1 == length-1

Source code in hexital/utils/indexing.py
def absindex(index: int | None, length: int) -> int:
    """Ensure's Index is a positive index, -1 == length-1"""
    if index is None:
        return length - 1
    if not valid_index(index, length):
        return length - 1
    if index < 0:
        return length + index
    return index