replace if elif elif with dictionary trick, and map-plus-lambda
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 Apr 2019 11:14:42 +0000 (12:14 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 Apr 2019 11:14:42 +0000 (12:14 +0100)
TLB/src/LFSR2.py

index 9cd97c31d8f81961c6a830724a360dd899a107ce..4baf2055db458fc58c17b78faa02caf1a14fe685 100644 (file)
@@ -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):