How to Save data of dictionary in Html file table

This simple script let you save the data in a dictionary as a table into an html file. I made this as an answer to a request to this video.

Merging 2 dictionaries

The code to transform data into html table

import os

a = {
	
	"First" : ["1","2"],
	"Second" : ["1","2","3"] 
}


data = ""
for k in a:
	data += "<td>" + k + "</td>"
	for d in a[k]:
		data += "<td>" + d + "</td>"
	data += "<tr>"

data = "<table border=1>" + data + "<table>"
print(data)
with open("file.html", "w") as file:
	file.write(data)

os.startfile("file.html")
The output of the code to generate a table in an html file

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.