Dividing every value in one list by every value in another list
<p>I am writing a function to find all the rational zeros of a polynomial and in need to divide each number in a list by each number in a list
Ex.</p>

<pre><code>list1 = [1,2,3,4,5,6,10,12,15,20,30,60]
list2 = [1,2,3,6]

zeros = [1/1,2/1,3/1,4/1,...,1/2,2/2,3/2,4/2,...1/3,2/3,3/3,4/3,etc...]
</code></pre>

<p>How would I accomplish this?
Edit:
Here is my code:</p>

<pre><code>from fractions import Fraction

def factor(x):
    x = abs(x)
    factors = []
    new_factors = []
    for n in range(1,x):
        if x % n == 0:
            factors.append(n)
            new_factors.append(n)
    for y in factors:
        new_factors.append(y * -1)
    new_factors = sorted(new_factors)
    return new_factors
print(factor(8))


def find_zeros(fnctn,pwr):
    last = fnctn[len(fnctn)]
    first = fnctn[0]
    P_s = factor(last)
    Q_s = factor(first)
    p_zeros = []
</code></pre>

<p>Would I do something like this:</p>

<pre><code>for x in P_s:
for y in Q_s:
    p_zeros.append(x/y)
</code></pre>

<p>You can achieve it by using <code>itertools.product()</code> and <code>map()</code></p>

<pre><code>&gt;&gt;&gt; from itertools import product
&gt;&gt;&gt; from operator import div
&gt;&gt;&gt; a = [1,2,3,4,5,6,10,12,15,20,30,60]
&gt;&gt;&gt; b = [1,2,3,6]
&gt;&gt;&gt; map(lambda x: div(x[1], x[0]), product(a, b))
[1, 2, 3, 6, 0, 1, 1, 3, 0, 0, 1, 2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
</code></pre>

<p><strong>Explanation:</strong></p>

<p><code>itertools.product()</code> gives cartesian product of two lists. For example, in your case:</p>

<pre><code>&gt;&gt;&gt; list(product(a, b))
[(1, 1), (1, 2), (1, 3), (1, 6), (2, 1), (2, 2), (2, 3), (2, 6), (3, 1), (3, 2), (3, 3), (3, 6), (4, 1), (4, 2), (4, 3), (4, 6), (5, 1), (5, 2), (5, 3), (5, 6), (6, 1), (6, 2), (6, 3), (6, 6), (10, 1), (10, 2), (10, 3), (10, 6), (12, 1), (12, 2), (12, 3), (12, 6), (15, 1), (15, 2), (15, 3), (15, 6), (20, 1), (20, 2), (20, 3), (20, 6), (30, 1), (30, 2), (30, 3), (30, 6), (60, 1), (60, 2), (60, 3), (60, 6)]
</code></pre>

<p>where as, <code>map(func, list)</code> is used to executed function <code>func</code> on every element of <code>list</code> and return new list</p>

python math