From b31ca0a7ab7aa9b1f0f47b36b5c8fcd2a6d95715 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 22 Apr 2019 11:10:04 +0100 Subject: [PATCH] use join trick instead of manually creating the exponent string --- TLB/src/LFSR2.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/TLB/src/LFSR2.py b/TLB/src/LFSR2.py index e4d4a5ac..3adfc359 100644 --- a/TLB/src/LFSR2.py +++ b/TLB/src/LFSR2.py @@ -29,18 +29,15 @@ class LFSRPolynomial(frozenset): def __str__(self): exponents = list(self) exponents.sort(reverse=True) - retval = "" - separator = "" + retval = [] for i in exponents: - retval += separator - separator = " + " if i == 0: - retval += "1" + retval.append("1") elif i == 1: - retval += "x" + retval.append("x") else: - retval += f"x^{i}" - return retval + retval.append(f"x^{i}") + return retval.join(" + ") def __repr__(self): exponents = list(self) -- 2.30.2