A loop is when the exact same Node appears more than once in a linked list. >>> root_node = Node(1) >>> root_node.next_node = Node(2) >>> root_node.next_node.next_node = Node(3) >>> root_node.next_node.next_node.next_node = Node(4) >>> root_node.has_l
(self)
| 24 | |
| 25 | @property |
| 26 | def has_loop(self) -> bool: |
| 27 | """ |
| 28 | A loop is when the exact same Node appears more than once in a linked list. |
| 29 | >>> root_node = Node(1) |
| 30 | >>> root_node.next_node = Node(2) |
| 31 | >>> root_node.next_node.next_node = Node(3) |
| 32 | >>> root_node.next_node.next_node.next_node = Node(4) |
| 33 | >>> root_node.has_loop |
| 34 | False |
| 35 | >>> root_node.next_node.next_node.next_node = root_node.next_node |
| 36 | >>> root_node.has_loop |
| 37 | True |
| 38 | """ |
| 39 | try: |
| 40 | list(self) |
| 41 | return False |
| 42 | except ContainsLoopError: |
| 43 | return True |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected