Generator incorrectly yielding empty lists
<p>I've read through <a href="http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained">The Python Yield Keyword Explained</a> here on this website, and have been playing around a bit with it in some of my functions, but for the life of me I haven't been able to work out this problem.</p>

<p>I have the following generator function, which when fed in example values:</p>

<pre><code>import collections
import itertools
import pprint
import copy

partition = []
def partition_prime_factors(partition_structure, prime_factors):
    # partition_structure is a list
    # prime_factors is a collections.Counter object

    global partition    

    for subsection_size in reversed(partition_structure):
        partition_structure.remove(subsection_size)        
        subsections = list(itertools.combinations(prime_factors.elements(), subsection_size))

        for subsection in subsections:
            prime_factors -= collections.Counter(subsection)
            partition.append(list(subsection))

            if len(prime_factors) == 0:
                pprint.pprint(globals()['partition'])

                yield copy.copy(partition)
            else:
                for j in partition_prime_factors(partition_structure, prime_factors):
                    pass

            prime_factors += collections.Counter(subsection)
            partition.remove(list(subsection))

        partition_structure.append(subsection_size)


print [i for i in partition_prime_factors([1, 3], collections.Counter([2, 2, 3, 5]))]


&gt;&gt;&gt; [[2, 2, 3], [5]]
&gt;&gt;&gt; [[2, 2, 5], [3]]
&gt;&gt;&gt; [[2, 3, 5], [2]]
&gt;&gt;&gt; [[2, 3, 5], [2]]
&gt;&gt;&gt; [[2], [2, 3, 5]]
&gt;&gt;&gt; [[2], [2, 3, 5]]
&gt;&gt;&gt; [[3], [2, 2, 5]]
&gt;&gt;&gt; [[5], [2, 2, 3]]
&gt;&gt;&gt; []
</code></pre>

<p>So the partitions are being correctly evaluated, but not yielded. HOW!?!?!?! LOL! I even make a copy of each partition before I yield in order to avoid being screwed by referencing the same object.</p>
