Files
Laboratori-PY/simulazioni/discografia/main.py
2024-03-22 17:01:42 +01:00

32 lines
618 B
Python

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"])