Merging two dictionaries together whilst adding keys but multiplying values I have two dictionaries and a merged dictionary:

dict1 = {-3: 0.3, -2: 0.1, 1: 0.8}
dict2 = {0: 0.3, 1: 0.5, -1: 0.7}
dict_merged = {}


I have code that basically merges the two together by adding keys together and multiplying values:
e.g.

for k1, v1 in dict1.items():
   for k2, v2 in dict2.items():
      new_key = k1 + k2
      if new_key in dict_merged:
          dict_merged[new_key] += v1 * v2
      else:
          dict_merged[new_key] = v1 * v2



Is there a faster way to do this, it feels like there should but dict comprehension doesn't seem helpful here. In the above example, we are going to get several contributes to the key "-3" for example.
It's standard to indent Python with 4 spaces. Not following this standard only makes your life and the life of people that have to interact with you harder.

You can just use the optional default argument to dict.get to remove the need for the if.

for k1, v1 in dict1.items():
    for k2, v2 in dict2.items():
        key = k1 + k2
        dict_merged[key] = v1 * v2 + dict_merged.get(key, 0)


Alternately you can change dict_merged to a collections.defaultdict, rather than a dict. This removes the need to use dict.get, and allows you to just us +=.
defaultdict takes a function that provides the default value to use. Since int() returns 0, we can just pass int as the function. As noted by Ilmari Karonen you can also use float as that returns 0.0 without any arguments.

import collections

dict_merged = collections.defaultdict(int)
for k1, v1 in dict1.items():
    for k2, v2 in dict2.items():
        dict_merged[k1 + k2] += v1 * v2