From 2d0c4c1678aa2caa7f0c42e90708ffa019dfc988 Mon Sep 17 00:00:00 2001 From: Walt Mankowski Date: Tue, 13 Oct 2020 21:18:20 -0400 Subject: replaced bounds checking with try clauses --- challenge-082/walt-mankowski/python/ch-2.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'challenge-082/walt-mankowski/python') diff --git a/challenge-082/walt-mankowski/python/ch-2.py b/challenge-082/walt-mankowski/python/ch-2.py index 662f0816d6..c9ef4de6f2 100644 --- a/challenge-082/walt-mankowski/python/ch-2.py +++ b/challenge-082/walt-mankowski/python/ch-2.py @@ -3,17 +3,21 @@ from sys import argv def is_interleave(a, b, c): if a == '' and b == '' and c == '': return 1 - elif c == '': - return 0 found = False - if len(a) > 0 and a[0] == c[0]: - found = True - return is_interleave(a[1:], b, c[1:]) + try: + if a[0] == c[0]: + found = True + return is_interleave(a[1:], b, c[1:]) + except IndexError: + pass - if len(b) > 0 and b[0] == c[0]: - found = True - return is_interleave(a, b[1:], c[1:]) + try: + if b[0] == c[0]: + found = True + return is_interleave(a, b[1:], c[1:]) + except IndexError: + pass if not found: return 0 -- cgit