From: Luke Kenneth Casson Leighton Date: Mon, 22 Apr 2019 11:14:42 +0000 (+0100) Subject: replace if elif elif with dictionary trick, and map-plus-lambda X-Git-Tag: div_pipeline~2165 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b294ae48d5ad135f00619a48bf524b044db9809e;p=soc.git replace if elif elif with dictionary trick, and map-plus-lambda --- 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):