songs = dict() artists = open("artisti.txt", "r") for artist in artists: artist = artist.split(";") artCode = artist[0].strip() songsFile = open(artist[1].strip(), "r") for song in songsFile: song = song.split(";", 1) year = song[0] title = song[1].strip() if year not in songs: songs[year] = [] songs[year].append({"artist": artCode, "title": title}) songsFile.close() artists.close() years = sorted(list(songs.keys())) for year in years: print(year + ":") for s in songs[year]: print(s["title"] + "\t" + s["artist"])