How does one generate a list of size N of all possibilities using a dictionary of size D?
The answer is elementary: recursion!

The underlying observation is that if you can create lists of size $N-1$, you can easily create lists of size $N$ by just appending any one of the $D$ values to every $N-1$ long list.

In pseudo code:

def all_possibilities(n, D) {
  if ( n == 0 ) {
    return [[]]
  }
  else {
    smaller = all_possibilities(n-1,D)
    return smaller.map { l =&gt; 
        D.map { 
          d =&gt; l ++ [d] 
        }
      }.flatten
  }
}


You can prove this correct by induction over $N$.