import csv


def write_to_csv(dictionary, header, csvfile):
    """Writes a dictionary from SQL query and list of headers into a csv file"""
    with open(csvfile, 'w') as a:
        writer = csv.DictWriter(a, delimiter=';', fieldnames=header, lineterminator='\n')
        writer.writeheader()
        for d in dictionary:
            writer.writerow(
                dict(
                    (k, v) for k, v in d.items()
                )
            )
    return csvfile