def inv_permutation(permutation):
    """Get the inverse of a permutation. Used to invert a transposition for example.

    Args:
        permutation (list or tuple): permutation to invert.

    Returns:
        list
    """
    inverse = [0] * len(permutation)
    for i, p in enumerate(permutation):
        inverse[p] = i
    return inverse