def dictCombinations(listdict):
 listdict = listdict.copy()
 if (len(listdict) == 0):
  return [{}]
 (k, vs) = listdict.popitem()
 res = dictCombinations(listdict)
 if (isinstance(vs, list) or isinstance(vs, tuple)):
  res = [dict(d, **{k: v}) for d in res for v in sorted(set(vs))]
 else:
  res = [dict(d, **{k: vs}) for d in res]
 return res

def dictCombinations ( listdict ) : listdict = listdict . copy ( ) if ( len ( listdict ) == 0 ) : return [ { } ] ( k , vs ) = listdict . popitem ( ) res = dictCombinations ( listdict ) if ( isinstance ( vs , list ) or isinstance ( vs , tuple ) ) : res = [ dict ( d , ** { k : v } ) for d in res for v in sorted ( set ( vs ) ) ] else : res = [ dict ( d , ** { k : vs } ) for d in res ] return res
iterates over dictionaries that go through every possible combination of key-value pairs as specified in the lists of values for each key in listdict .