From 2d3e8ec9b0b496e35a208b896706ac80193ee62e Mon Sep 17 00:00:00 2001 From: Louie Tan Date: Sat, 21 Oct 2017 01:41:04 +0800 Subject: [PATCH] LinkedList lazy iterator --- utilities/python/linked_list.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utilities/python/linked_list.py b/utilities/python/linked_list.py index 13a25b8b..011d66b0 100644 --- a/utilities/python/linked_list.py +++ b/utilities/python/linked_list.py @@ -71,3 +71,10 @@ def linked_list_delete_index(linked_list, index): raise ValueError node.next = node.next.next return linked_list + +def linked_list_iter(linked_list): + '''Lazy iterator over each node in the linked list''' + node = linked_list + while node is not None: + yield node + node = node.next