def dicts_to_html_table(a_list):
    """
    Converts a list of dictionaries to a HTML table. Keys become the header of the table.
    Useful while sending email from the code

    :param list(dict) a_list: values in the form of list of dictionaries

    :return: HTML table representation corresponding to the values in the lists
    :rtype: str
    """
    keys = sorted(a_list[0].keys())
    header = "<tr><th>%s</th></tr>" % ("</th><th>".join(keys))
    body = ""
    if len(a_list) > 1:
        for sub_dict in a_list:
            body += "<tr><td>%s</td></tr>\n" % ("</td><td>".join([sub_dict[key] for key in keys]))
    return "<table>%s\n%s</table>" % (header, body)