Interesting problem!
Another classic case of Python over-compression! List comprehensions can be a nightmare, and I hate to see them thrown at beginners. I also noticed a few potential problems with that approach, so I'd like to offer an alternative. For a value add, this will also keep track of the power of each term. I've commented the approach.
# This is hopefully self-explanatory.
poly = "4x^2 - 3x^3 - 2x + 2"
# We made this regex more complicated in order to capture an entire
# term of a polynomial. Here's how that works:
# ([+-]|) - The first capture group, contain the sign or (|)
# nothing.
# \s* - Allow whitespace between the sign and the term.
# ([0-9]+) - The second capture group, contain the coefficient.
# ([xX]|) - Match the variable or nothing.
# (\^[0-9]+|) - Match the exponent or nothing. Notice we escape the caret.
matches = re.finditer(r'([+-]|)\s*([0-9]+)([xX]|)(\^[0-9]+|)', poly)
# Now we parse the results of the regex...
terms = list() # Create a list to store our processed terms.
for match in matches: # Iterate our matches.
# Step 1: Parse the groups' contents.
negative = match.group(1) == '-' # Check if the sign is negative.
coef = int(match.group(2)) # Retrieve the coefficient as an integer.
has_variable = bool(match.group(3)) # Check whether there's a variable.
exponent_str = match.group(4) # Get the exponent group.
if exponent_str:
# There's an exponent, remove the caret and turn it into an
# integer.
exponent = int(exponent_str[1:])
else:
# There's no exponent, if there's a variable the power of this term
# is 1, otherwise it's 0.
exponent = 1 if has_variable else 0
# Step 2: Create a (coefficient, power) tuple and add it to the list of
# terms.
if negative:
# Make the coefficient negative if the sign was a -.
coef *= -1
# Add a tuple containing the coefficient and exponent to our list of
# terms.
terms.append((coef, exponent))
# Optional: sort the terms in order of power (descending).
terms.sort(key=lambda tpl: -tpl[1])
# Print the output.
print(terms)
This will output
[(-3, 3), (4, 2), (-2, 1), (2, 0)]