*** Nova polynomial subtract*** 

This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1)   [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe)  [#3](http://www.codewars.com/kata/5714041e8807940ff3001140 )   [#4](http://www.codewars.com/kata/571a2e2df24bdfd4e20001f5))


Consider a polynomial in a list where each element in the list element corresponds to the factors. The factor order is the position in the list. The first element is the zero order factor (the constant).

p = [a0, a1, a2, a3] signifies the polynomial a0 + a1x + a2x^2 + a3*x^3

In this kata subtract two polynomials:

```python 
poly_subtract([1, 2], [1] ) = [0, 2]
poly_subtract([2, 4], [4, 5] ) = [-2, -1]
```
The first and second katas of this series are preloaded in the code and can be used: 

 * [poly_add](http://www.codewars.com/kata/nova-polynomial-1-add-1) 
 * [poly_multiply](http://www.codewars.com/kata/570eb07e127ad107270005fe).

Source: codewars | Difficulty: EASY
Tags: Data structures

Complete search

Starter code: def poly_subtract(p1, p2):
	

Solutions:
from itertools import zip_longest

def poly_subtract(p1, p2):
	return [x - y for (x, y) in zip_longest(p1, p2, fillvalue=0)]


from itertools import zip_longest

def poly_subtract(a, b):
	return [x - y for (x, y) in zip_longest(a, b, fillvalue=0)]


def poly_subtract(p1, p2):
	p1length = len(p1)
	p2length = len(p2)
	length = max(p1length, p2length)
	list = []
	for i in range(0, length):
		a = 0
		b = 0
		if i < p1length:
			a = p1[i]
		if i < p2length:
			b = p2[i]
		list.append(a - b)
	print(list)
	return list


def poly_subtract(p1, p2):
	res = []
	longest_p = max(len(p1), len(p2))
	for i in range(longest_p):
		res.append((p1[i] if i < len(p1) else 0) - (p2[i] if i < len(p2) else 0))
	return res