I want to take a dictionary, where the key is a string and the value a list of strings, and be able to print it in a new file where the keys are alphabetized, as well as the values. I'm not having any issue with the values. The problem lies in figuring out how to get the keys to print in the file alphabetically. Here is what I have:
def write_movie_info(string, aDict):
newFile = open(string, 'w')
myList = []
for movie in aDict:
aDict[movie].sort()
myList.append([movie] + aDict[movie])
for aList in myList:
joiner = ", ".join(aList[1:])
newFile.write(aList[0] + ': ' + joiner + '\n')
and the dictionary is:
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)