A Check Point security event pipeline stores events in a singly linked list. Implement the list construction and determine whether the list contains a loop, such as one caused by an incorrect event-linking operation.
The function receives a list of event identifiers and a loop position. It must build the linked list, connect the final node to the node at that position when applicable, and detect the loop using constant auxiliary space.
Implement has_loop(values, loop_index). values is a list of integers used to create one node per value. loop_index is the zero-based index of the node that the final node should reference, or -1 when the list should terminate at None. Return True if the constructed list contains a loop, otherwise return False.
Use a singly linked-list node with value and next fields. Do not traverse indefinitely, and do not use a set of visited nodes in the primary solution.
def has_loop(values, loop_index):