From 9e33388d47604ac397965d081343631d8eff37e8 Mon Sep 17 00:00:00 2001 From: Vuong Thanh Tung Date: Wed, 16 Sep 2020 17:08:41 +0700 Subject: [PATCH] Update cartalk1.py --- code/cartalk1.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/code/cartalk1.py b/code/cartalk1.py index 2d1e4d2..45a8b56 100644 --- a/code/cartalk1.py +++ b/code/cartalk1.py @@ -19,17 +19,13 @@ def is_triple_double(word): returns: bool """ - i = 0 - count = 0 - while i < len(word)-1: + word_len = len(word) + if word_len < 6: + return False + for i in range(word_len - 6): if word[i] == word[i+1]: - count = count + 1 - if count == 3: + if word[i+2] == word[i+3] and word[i+4] == word[i+5]: return True - i = i + 2 - else: - i = i + 1 - 2*count - count = 0 return False