Answer:
with open("file1.txt", "r") as file:
lines = file.readlines()
mydict = dict()
for x in range(0, len(lines) - 1, 2):
mydict[lines[x]] = lines[x-1]
dict_keys = sorted(mydict.keys)
sorted_dict ={}
for key in dict_keys:
sorted_dict[key] = mydict[key]
with open("output_keys.txt", "a+") as writn:
for key, value in sorted_dict.items():
writn.write(key: value)
writn.write("\\")
dict_values = sorted(mydict.values)
with open("output_titles", "a+") as title:
for name in dict_values:
title.write(name)
title.write("\\")
Step-by-step explanation:
The python program above reads in the file context, files.txt, and creates a dictionary of the file with the number of seasons as the key and movie title as the value. The sorted dictionary is saved in the output_keys.txt file and the titles in output_titles.txt file.