Sorting both the keys and values(list) in dcitionary
#I have a function which takes 2 parameters, a string and a dictionary. The string will represent the filename to which to write. The keys in the dictionary will be strings representing movie titles. The values in the dictionary will be lists of strings representing performers in the corresponding movie. The function should write the list of movies to the file given by the filename using the following format: # Title: Actor 1, Actor 2, Actor 3, etc. #The movies and the actor names should be sorted alphabetically. #Write your function here! def write_movie_info(filename, movies): _file = open(filename, "a") for key,values in movies.items(): _file.write(str(key) + ":" + " ") i = 1 for each_value in values: if i < len(values): _file.write(str(each_value) + ','+" ") else: _file.write(str(each_value)) i += 1 _file.write('\n') movies = {"Chocolat": ["Juliette Binoche", "Judi Dench", "Johnny Depp", "Alfred Molina"], "Skyfall": ["Judi Dench", "Daniel Craig", "Javier Bardem", "Naomie Harris"]} write_movie_info("Test.txt", movies) ***************************** The expected result is : # Chocolat: Alfred Molina, Johnny Depp, Judi Dench, Juliette Binoche # Skyfall: Daniel Craig, Javier Bardem, Judi Dench, Naomie Harris but my code is printing: #Chocolat: Juliette Binoche, Judi Dench, Johnny Depp, Alfred Molina #Skyfall: Judi Dench, Daniel Craig, Javier Bardem, Naomie Harris Please help me in sorting both the keys and values list alphabetically. I tried sort, sorted but it doesnt work.