import json f = open("words.json") words = json.load(f) f.close() freqf = open("most_frequent") freq_words = freqf.read().splitlines() freqf.close() html = "" for idx, fw in enumerate(freq_words): for word in words: if word["word"] == fw: html += f"{fw}{word['track']}\n" htmlf = open("frequent_words.html", "w") htmlf.write(html) htmlf.close()