Following a challenge on HackerRank, I want to find the sum of all numbers that have no more than `x 4's`, `y 5's`, and `z 6's` `module 10^9 + 7`. I'd like to know how I could improve this code below both for style and performance. Also, what's the canonical way to get unique permutations of a list that can include repeated elements? 

```
import itertools
import sys
import collections

#create initial list based on input
x, y, z = map(int, sys.stdin.readline().split(' '))
permute_list = [4]*x + [5]*y + [6]*z

# collect iterators to permutations of all possible lengths
permuted = []
for i in range(1,(x+y+z+1)):
    permuted.append(itertools.permutations(permute_list, i))

# collect unique permutations from iterators
# there will be many repeats, anyway to avoid this inefficiency?
dynamic_table = collections.defaultdict(lambda: 0)
mod_var = (10**9 + 7)
for it in permuted:
    for i in it:
        new_sum = ''.join(map(str, i))
        if not dynamic_table[new_sum]:
            dynamic_table[new_sum] = int(new_sum)

print(sum(dynamic_table.values()) % mod_var)

```

I tried a few ways of doing this. What most surprised me is that implementing with a `dictionary`, as above, seems to beat a `set` implementation by about 30%, time-wise. Why is this? Also, what are some better ways to implement this and/or tweaks to the above code?