Complete the function that calculates the derivative of a polynomial. A polynomial is an expression like: 3x^(4) - 2x^(2) + x - 10

### How to calculate the derivative:

* Take the exponent and multiply it with the coefficient
* Reduce the exponent by 1

For example: 3x^(4) --> (4*3)x^((4-1)) = 12x^(3)

### Good to know:

* The derivative of a constant is 0 (e.g. 100 --> 0)
* Anything to the 0th exponent equals 1 (e.g. x^(0) = 1)
* The derivative of the sum of two function is the sum of the derivatives

Notes:
* The exponentiation is marked with "^"
* Exponents are always integers and >= 0
* Exponents are written only if > 1
* There are no spaces around the operators
* Leading "+" signs are omitted

See the examples below.

## Examples
```python
derivative("-100")      = "0"
derivative("4x+1")      = "4"      # = 4x^0 + 0
derivative("-x^2+3x+4") = "-2x+3"  # = -2x^1 + 3x^0 + 0
```

Difficulty: EASY
Tags: Mathematics

Starter code:
def derivative(eq):
	

Solutions:
import re
my_regexp = '(?P<sign>[+\\-]?)(?P<coeff>\\d*)x(?:\\^(?P<exp>\\d+))?'
as_int = lambda s: int(s) if s else 1

def derivative(eq):
	result = ''
	for monom in re.finditer(my_regexp, eq):
		(sign, coeff, exp) = monom.groups()
		(coeff, exp) = list(map(as_int, (coeff, exp)))
		coeff *= exp
		exp -= 1
		result += ('{sign}{coeff}' if exp == 0 else '{sign}{coeff}x' if exp == 1 else '{sign}{coeff}x^{exp}').format(sign=sign, coeff=coeff, exp=exp)
	return result if result else '0'


import re
DERIVATE = re.compile('([+-]?)(\\d*)x\\^?(\\d*)')

def derivative(eq):
	rawDerivate = ''.join(('{}{}x^{}'.format(sign, int(coef or '1') * int(exp or '1'), int(exp or '1') - 1) for (sign, coef, exp) in DERIVATE.findall(eq)))
	derivate = re.sub('x\\^0|\\^1\\b', '', rawDerivate)
	return derivate or '0'


from re import finditer, sub

def derivative(equation):
	mx = ''
	for exp in finditer('([\\+\\-])?(\\d*)?x\\^?(\\d+)?', equation):
		sign = -1 if exp.group(1) == '-' else 1
		scalar = int(exp.group(2)) if exp.group(2) else 1
		power = int(exp.group(3)) if exp.group(3) else 1
		mx += f'{sign * power * scalar}x^{power - 1}+'
	mx = sub('x\\^0\\b', '', mx)
	mx = sub('x\\^1\\b', 'x', mx)
	mx = sub('\\+\\-', '-', mx)
	if not mx:
		return '0'
	return mx[:-1]


import re
derivative = lambda s: re.sub('\\^1(?=[-+])', '', re.sub('\\+-', '-', '+'.join([['', f"{int(i[0] if i[0] and i[0] not in '+-' else [1, -1][i[0] == '-']) * int(i[-1] or 1)}"][bool(i[-2])] + (f'x^{[0, int(i[-1]) - 1][bool(i[-2])]}' if i[-1] else '') for i in re.findall('([-+]?\\d*)(x?)\\^?(\\d*)', s)]))).strip('+') or '0'


import re

def derivative(eq):
	monos = re.findall('([+-]?)(\\d*)x\\^?(\\d*)', eq)
	result = ''
	for (sign, coef, exp) in monos:
		exp = int(exp or '1')
		coef = int(coef or '1') * exp
		result += f'{sign}{coef}x^{exp - 1}'
	result = re.sub('x\\^0|\\^1\\b', '', result)
	return result or '0'


import re

def derivative(eq):
	res = []
	eq = re.sub('\\bx', '1x', eq)
	for (const, var, exp) in re.findall('([+-]?\\d+)(x?)\\^?(\\d*)', eq):
		if not var:
			continue
		if not exp:
			res.append(const)
			continue
		(const, exp) = (int(const), int(exp))
		const *= exp
		if exp == 2:
			res.append('%+dx' % const)
		else:
			res.append('%+dx^%d' % (const, exp - 1))
	res = ''.join(res).strip('+')
	return res if res else '0'


import re
nomial = re.compile('(?P<sign>[\\+-]?)(?P<coef>[0-9]*)(?P<x>[a-z]?)\\^?(?P<exp>[0-9]*)')

def derive(eq):
	if not eq:
		return ''
	m = nomial.match(eq)
	c = int(m.group('coef') or '1')
	exp = int(m.group('exp') or '1')
	if not m.group('x'):
		r = ''
	elif not m.group('exp'):
		r = m.group('sign') + str(c)
	elif m.group('exp') == '2':
		r = m.group('sign') + str(c * 2) + m.group('x')
	else:
		r = m.group('sign') + str(c * exp) + m.group('x') + '^' + str(exp - 1)
	return r + derive(eq[m.end():])

def derivative(eq):
	return derive(eq) or '0'


import re
str2int = lambda s: int(s + '1' * (not s[-1:].isdigit()))

def monomial(args):
	(c, p) = map(str2int, args)
	return '%+d' % (c * p) + 'x' * (p > 1) + '^%d' % (p - 1) * (p > 2)

def derivative(eq):
	return ''.join(map(monomial, re.findall('(-?\\d*)x\\^?(\\d*)', eq))).lstrip('+') or '0'


def derivative(eq):
	r = '+'.join([s for s in [derive(w) for w in eq.replace('+', ' ').replace('-', ' -').replace('-x', '-1x').split()] if s])
	return r.replace('+-', '-') if r else '0'

def derive(term):
	if 'x' not in term:
		return ''
	if '^' not in term:
		return term.split('x')[0] if term.split('x')[0] else '1'
	(a, b) = [int(w) if w else 1 for w in term.split('x^')]
	(a, b) = (a * b, b - 1)
	return ('' if a == 1 else str(a)) + 'x' + ('^' + str(b) if b > 1 else '')


from re import findall

def derivative(eq):
	monos = ['{}', '{}x', '{}x^{}']
	res = ''
	for t in findall('(\\+|-)?(\\d+)?x(?:\\^(\\d+))?', eq):
		(a, b) = (int(x) if x else 1 for x in t[1:])
		res += t[0] + monos[(b > 1) + (b > 2)].format(a * b, b - 1)
	return res if res else '0'