def deep_merge(source, dest):
for key, value in source.iteritems():<EOL><INDENT>if key in dest:<EOL><INDENT>if isinstance(value, dict) and isinstance(dest[key], dict):<EOL><INDENT>deep_merge(value, dest[key])<EOL>continue<EOL><DEDENT>elif isinstance(value, list) and isinstance(dest[key], list):<EOL><INDENT>for item in value:<EOL><INDENT>if item not in dest[key]:<EOL><INDENT>dest[key].append(item)<EOL><DEDENT><DEDENT>continue<EOL><DEDENT><DEDENT>dest[key] = value<EOL><DEDENT>
Deep merges source dict into dest dict.