def METHOD_NAME(dict_list, filename, mode="w"):
    """Write a list of dicts to a csv file."""
    if dict_list:
        keys = dict_list[0].keys()
        with open(filename, mode=mode, encoding="utf-8") as output_file:
            dict_writer = csv.DictWriter(output_file, keys)
            dict_writer.writeheader()
            dict_writer.writerows(dict_list)