Your program should read from the file, storing the names and corresponding email addresses in a dictionary as key-value pairs. Then, the program should display a menu that lets the user enter the numbers 1 through 5, each corresponding to a different menu item: When the user enters 5, the program should write the names and email addresses in alphabetical order by first name to the file phonebook.out You can use the
sorted()function which accepts a dictionary argument to sort a dictionary based on Key
This is my code:
def write_to_file(contact): file = open("phonebook.out", "w") contactsort = dict(sorted(contact.items())) phonebook.write(contact) phonebook.close
However, this code isn't working. I'm not sure why, so any help is appreciated. thank you.