This may help (not exactly one line):
def polynonmial_equation(coefficients):
degree = len(coefficients) - 1
temp = "".join(map(lambda x: "" if x[1] == 0 else [" - ", " + "][x[1]> 0] + [str(abs(x[1])) + "*", ""][abs(x[1]) == 1] + "x^" + str(degree -x[0]), enumerate(reversed(coefficients)))).strip()
return temp if temp.startswith('-') else temp[1:]
More re-presentation of the form above:
def polynonmial_equation(coefficients):
degree = len(coefficients) - 1
temp = "".join(map(lambda x: "" if x[1] == 0 else
[" - ", " + "][x[1] > 0] +
[str(abs(x[1])) + "*", ""][abs(x[1]) == 1] +
"x^" + str(degree - x[0]),
enumerate(reversed(coefficients)))).strip()
return temp if temp.startswith('-') else temp[1:]
print(polynonmial_equation([0, 0, 0, 1, 1]))
print(polynonmial_equation([0, 0, 0, 1, -1]))
print(polynonmial_equation([0, 0, 0, -1, -1]))
print(polynonmial_equation([0, 0, 0, -1, 1]))
print()
print(polynonmial_equation([0, 0, 0, 1, 3]))
print(polynonmial_equation([0, 0, 0, 1, -3]))
print(polynonmial_equation([0, 0, 0, -1, -3]))
print(polynonmial_equation([0, 0, 0, -1, 3]))
print()
print(polynonmial_equation([1, 2, 3, 4, 5]))
print(polynonmial_equation([-1, 2, -3, 4, -5]))
print(polynonmial_equation([-1, 2, 0, 4, -5]))
print(polynonmial_equation([0, 0, 6, -1, -3]))
print(polynonmial_equation([0, -3, 4, -1, 0]))
And the conclusion:
x^4 + x^3
- x^4 + x^3
- x^4 - x^3
x^4 - x^3
3*x^4 + x^3
- 3*x^4 + x^3
- 3*x^4 - x^3
3*x^4 - x^3
5*x^4 + 4*x^3 + 3*x^2 + 2*x^1 + x^0
- 5*x^4 + 4*x^3 - 3*x^2 + 2*x^1 - x^0
- 5*x^4 + 4*x^3 + 2*x^1 - x^0
- 3*x^4 - x^3 + 6*x^2
- x^3 + 4*x^2 - 3*x^1