I assume you want the cartesian product of all the keys? So if you had another entry, "foo", with values [1, 2, 3], then you'd have 18 total entries?
First, put the values in a list, where each entry is one of the possible variants in that spot. In your case, we want:
[[{'debug': 'on'}, {'debug': 'off'}], [{'locale': 'de_DE'}, {'locale': 'en_US'}, {'locale': 'fr_FR'}]]
To do that:
>>> stuff = []
>>> for k,v in variants.items():
blah = []
for i in v:
blah.append({k:i})
stuff.append(blah)
>>> stuff
[[{'debug': 'on'}, {'debug': 'off'}], [{'locale': 'de_DE'}, {'locale': 'en_US'}, {'locale': 'fr_FR'}]]
Next we can use a Cartesian product function to expand it...
>>> def cartesian_product(lists, previous_elements = []):
if len(lists) == 1:
for elem in lists[0]:
yield previous_elements + [elem, ]
else:
for elem in lists[0]:
for x in cartesian_product(lists[1:], previous_elements + [elem, ]):
yield x
>>> list(cartesian_product(stuff))
[[{'debug': 'on'}, {'locale': 'de_DE'}], [{'debug': 'on'}, {'locale': 'en_US'}], [{'debug': 'on'}, {'locale': 'fr_FR'}], [{'debug': 'off'}, {'locale': 'de_DE'}], [{'debug': 'off'}, {'locale': 'en_US'}], [{'debug': 'off'}, {'locale': 'fr_FR'}]]
Note that this doesn't copy the dicts, so all the {'debug': 'on'}
dicts are the same.