################################################################################
# Wrap a list of dictionaries into an HTML table
# Launch a browser with the resulting html
################################################################################
import webbrowser

list = [ {'student_id': '1', 'lname': 'Burns', 'fname': 'Barbara',   'ssn': '000-01-0001', 'sex': 'F' },
         {'student_id': '2', 'lname': 'Cambria', 'fname': 'Vincent', 'ssn': '000-01-0002', 'sex': 'M' },
         {'student_id': '3', 'lname': 'Davidson', 'fname': 'Duncan', 'ssn': '000-01-0003', 'sex': 'M' },
         {'student_id': '4', 'lname': 'Smith', 'fname': 'David',     'ssn': '000-01-0004', 'sex': 'M' } ]

output = """
<html>
<h2>Display a List of Dictionaries in an HTML table</h2>
<table border='2' >
<tr bgcolor=cyan >
<th> ID <th> LAST NAME <th>FIRST NAME <th> SSN <th> SEX</tr> 
</tr>
"""

for  dict  in  list :
      output += "<tr>"								                #print each value
      output += F"<td> {dict['student_id']} <td> {dict['lname']}" 
      output += F"<td> {dict['fname']}      <td> {dict['ssn']} <td> {dict['sex']}" 
      output += "</tr> \n"

output += "</table> \n"
output += "</html>  \n"

#print(output)

htmlfile = 'C:/users/samsu/desktop/output.html'
file = open(htmlfile,'w')
file.write(output)
file.close()

webbrowser.open_new(htmlfile)