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.

Python and dictionaries: merging and summing key values
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
My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts