From b294ae48d5ad135f00619a48bf524b044db9809e Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 22 Apr 2019 12:14:42 +0100 Subject: [PATCH] replace if elif elif with dictionary trick, and map-plus-lambda --- TLB/src/LFSR2.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/TLB/src/LFSR2.py b/TLB/src/LFSR2.py index 9cd97c31..4baf2055 100644 --- a/TLB/src/LFSR2.py +++ b/TLB/src/LFSR2.py @@ -32,14 +32,8 @@ class LFSRPolynomial(set): return exponents def __str__(self): - retval = [] - for i in self.exponents: - if i == 0: - retval.append("1") - elif i == 1: - retval.append("x") - else: - retval.append(f"x^{i}") + expd = {0: "1", 1: 'x', 2: "x^{}"} # case 2 isn't 2, it's min(i,2) + retval = map(lambda i: expd[min(i,2)].format(i), self.exponents) return " + ".join(retval) def __repr__(self): -- 2.30.2