use join trick instead of manually creating the exponent string
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 Apr 2019 10:10:04 +0000 (11:10 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 22 Apr 2019 10:10:04 +0000 (11:10 +0100)
TLB/src/LFSR2.py

index e4d4a5ac2455bdf9a0bbda521aeb01092a5dbc18..3adfc3596276598ba6b4817ec446c16122bcdbcc 100644 (file)
@@ -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)