Generate all possible dictionary combinations given number of steps?
<p>Assume:</p>

<p>only 4 letters (a, b, c, d) are used</p>

<p>Say I have a dictionary comprise of occurrences(>=0) of the 4 letters</p>

<pre><code>d = {"a":1, "b":2, "c":1, "d":3}
</code></pre>

<p>and I am given a "steps" number.</p>

<p>I want to find all the dictionaries that are possible given a "steps" number of occurrence subtractions.</p>

<p>For example</p>

<pre><code># given the above dictionary and a steps of 2
moo = {"a":1, "b":1, "c":1, "d":2}
# moo is a possibility because I simply took away 1 b and 1 d
# how do I find all the possibilities? (note: occurrences cannot be negative)
</code></pre>

<p>edit: steps as in exactly 2 steps</p>

<p>Note: I want to find all the "moo"s, or all the dictionaries that are possible given a reference dictionary and a number of steps.  I don't care about testing if two dictionaries meet the steps requirement.</p>

<p>I think I came up with some recursive code to solve this problem:</p>

<pre><code>def genDict(d, steps):
    if steps == 0:
        return [d]
    dList = []
    for key, value in d.items():
        if value &gt; 0:
            temp = dict(d)
            temp[key] = value -1
            dList += genDict(temp, steps-1)
    return dList
</code></pre>

<p>Anyone got a non-recursive solution that won't hog up memory?</p>
