From 7ac7ecdea0edfb97743d08f63d49939c9a693a6c Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 11 May 2017 06:43:32 +0200 Subject: [PATCH 1/3] Simplify repeat_last() --- data_structure.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/data_structure.py b/data_structure.py index debd20446..cde9ff490 100755 --- a/data_structure.py +++ b/data_structure.py @@ -54,14 +54,11 @@ def handle_read(handle): def handle_write(handle, prop): handle_delete(handle) - temp_handle[handle] = {"prop" : prop} def handle_check(handle, prop): - if handle in handle_check and \ - prop == handle_check[handle]['prop']: - return True - return False + return bool(handle in handle_check and + prop == handle_check[handle]['prop']) ##################################################### @@ -75,13 +72,10 @@ def repeat_last(lst): and then keep repeating the last element, use with terminating input """ - i = -1 - while lst: - i += 1 - if len(lst) > i: - yield lst[i] - else: - yield lst[-1] + for x in lst: + yield x + while True: + yield lst[-1] def match_long_repeat(lsts): -- GitLab From c0a8b4cc2e1260072eb1b7c13dc6666cf109fab8 Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 11 May 2017 08:31:03 +0200 Subject: [PATCH 2/3] Deal with the empty list --- data_structure.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structure.py b/data_structure.py index cde9ff490..355e804c2 100755 --- a/data_structure.py +++ b/data_structure.py @@ -74,8 +74,8 @@ def repeat_last(lst): """ for x in lst: yield x - while True: - yield lst[-1] + while True: + yield lst[-1] def match_long_repeat(lsts): -- GitLab From 771872171316a9d08606ef332fbe41e63b99fe12 Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 11 May 2017 08:33:21 +0200 Subject: [PATCH 3/3] Deal with empty list --- data_structure.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structure.py b/data_structure.py index 355e804c2..30164e1a1 100755 --- a/data_structure.py +++ b/data_structure.py @@ -74,8 +74,8 @@ def repeat_last(lst): """ for x in lst: yield x - while True: - yield lst[-1] + while lst: + yield lst[-1] def match_long_repeat(lsts): -- GitLab