Skip to content

Commit 611f6aa

Browse files
__str__ method update
1 parent 0e87742 commit 611f6aa

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

maths/radix2_fft.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,23 @@ def __multiply(self):
175175
# Overwrite __str__ for print(); Shows A, B and A*B
176176
def __str__(self):
177177
A = "A = " + " + ".join(
178-
[
179-
f"{self.polyA[i]}*x^{i}"
180-
for i in range(self.len_A)
181-
]
178+
f"{coef}*x^{i}"
179+
for coef, i in enumerate(
180+
self.polyA[: self.len_A]
181+
)
182182
)
183183
B = "B = " + " + ".join(
184-
[
185-
f"{self.polyB[i]}*x^{i}"
186-
for i in range(self.len_B)
187-
]
184+
f"{coef}*x^{i}"
185+
for coef, i in enumerate(
186+
self.polyB[: self.len_B]
187+
)
188188
)
189189
C = "A*B = " + " + ".join(
190-
[
191-
f"{self.product[i]}*x^{i}"
192-
for i in range(len(self.product))
193-
]
190+
f"{coef}*x^{i}"
191+
for coef, i in enumerate(self.product)
194192
)
195193

196-
return A + "\n \n" + B + "\n \n" + C
194+
return "\n\n".join((A, B, C))
197195

198196

199197
# Unit tests

0 commit comments

Comments
 (0)