Answer:
filename = input("Enter file name: ")
movie_container = list()
with open(filename, "r") as movies:
content = movies.readlines()
for movie in content:
holder = movie.split("\t")
movie_container.append((holder[0], holder[1], holder[2], holder[3]))
movie_container = sorted(movie_container, key= lambda movie: movie[0])
for movie in movie_container:
movie_stars = movie[3].split(",")
name_split = [names.split(" ") for names in movie_stars]
movie_stars.clear()
name_split = sorted(name_split, key= lambda names: names[1])
for name in name_split:
full_name = " ".join(name)
print( full_name)
movie_stars.append(full_name)
movie[3] = movie_stars
print(movie_container)
Step-by-step explanation:
The python code uses the open function to open and read in the input file from the standard user prompt. The title of the movies and the stars are all sorted alphabetically and display at the output.