human
Can you show me a Python function to write a dictionary to file.
assistant
Here is a Python function to write a dictionary to file

import json

def write_dict_to_file(dictionary, filename):
        """
        Write a dictionary to file.
        """
        with open(filename, 'w') as f:
            for key, value in list(dictionary.items()):
                f.write("%s : %s\n" % (key, value))

# Enter the dictionary
dictionary = {"key1": "value1", "key2": "value2"}

# Calling the function
print((write_dict_to_file(dictionary, "test.json")))

#Example Output
# None

#Remember to inspect code for bugs.