def __getitem__(self, idx: int) -> Operation:
        """
        The indexing is expensive in doubly linked list, we should prevent direct access besides [0] and [-1].
        """
        if self.start is None:
            raise ValueError("Cannot index an empty list.")
        if idx >= len(self):
            raise ValueError("Index out of range")
        if idx == 0:
            return self.start.op
        elif idx == -1:
            return self.end.op
        raise ValueError("Doubly linked list does not support indexing other than 0, -1.")

        The indexing is expensive in doubly linked list, we should prevent direct access besides [0] and [-1].
        
coremltools/converters/mil/mil/utils.py