def _list_select(shape_var, index):
    """
    Sometimes we need to select a specific item from a list. If that item
    is known at compile time, extract it as a const. Otherwise, if it's
    symbolic, use gather.
    """
    if shape_var.can_be_folded_to_const():
        res = mb.const(val=shape_var.val[index])
    else:
        if is_current_opset_version_compatible_with(target.iOS17):
            # IOS17 `gather` requires non-negative indices.
            index = mb.select(
                cond=mb.greater_equal(x=index, y=0),
                a=index,
                b=mb.add(x=index, y=_utils.pymil_value_at(mb.shape(x=shape_var), 0)),
            )
        res = mb.gather(x=shape_var, indices=index)
    return res

    Sometimes we need to select a specific item from a list. If that item
    is known at compile time, extract it as a const. Otherwise, if it's
    symbolic, use gather.
    
coremltools/converters/mil/frontend/torch/ops.py