# Read input file name
filename = input().strip()
# Read file contents using readlines()
with open(filename, 'r') as file:
lines = file.readlines()
# Dictionary: seasons -> list of TV shows
tv_dict = {}
# Process the input file (two lines per record)
i = 0
while i < len(lines) - 1:
seasons_line = lines[i].strip()
show_line = lines[i + 1].strip()
if seasons_line.isdigit():
seasons = int(seasons_line)
tv_dict.setdefault(seasons, []).append(show_line)
i += 2
# -------------------
# Write output_keys.txt
# Sorted by number of seasons (greatest to least)
# -------------------
with open('output_keys.txt', 'w') as out_keys:
for seasons in sorted(tv_dict.keys(), reverse=True):
shows = '; '.join(tv_dict[seasons])
out_keys.write(f"{seasons}: {shows}\n")
# -------------------
# Write output_titles.txt
# Sorted by TV show title (reverse alphabetical)
# -------------------
show_list = []
for seasons, shows in tv_dict.items():
for show in shows:
show_list.append(show)
with open('output_titles.txt', 'w') as out_titles:
for show in sorted(show_list, reverse=True):
out_titles.write(f"{show}\n")
To embed this project on your website, copy the following code and paste it into your website's HTML: