From 2b49e4b082f6c049c4582891a4db7ee782631c7c Mon Sep 17 00:00:00 2001 From: ACKERMANNGUE <gawen.ackermann@etu.hesge.ch> Date: Thu, 16 Dec 2021 10:38:22 +0100 Subject: [PATCH] refactoring add --- polynomial.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/polynomial.py b/polynomial.py index 235facc..c2ccbb8 100644 --- a/polynomial.py +++ b/polynomial.py @@ -60,20 +60,10 @@ class Polynomial: a = list(self.value) b = list(other.value) - a_count = len(a) - b_count = len(b) - if a_count > b_count: - diff = a_count - b_count - for x in range(diff): - b.append(0) - else: - diff = b_count - a_count - for x in range(diff): - a.append(0) - - c = [0] * len(a) - for x in range(len(a)): - c[x] = a[x] + b[x] + c = [] + # itertools pad 0 to the lowest list + for (a, b) in itertools.zip_longest(a, b, fillvalue=0): + c.append(a + b) return Polynomial(tuple(c)) -- GitLab