12.10 LAB: Sorting TV Shows (dictionaries and lists) Write a program that first reads in the name of an input file and then
12.10 LAB: Sorting TV Shows (dictionaries and lists)
Write a
Sort the dictionary by key (greatest to least) and output the results to a file named output_keys.txt. Separate multiple TV shows associated with the same key with a semicolon (;), ordering by appearance in the input file. Next, sort the dictionary by values (in reverse alphabetical order), and output the results to a file named output_titles.txt.
Ex: If the input is:
file1.txtand the contents of file1.txt are:
20 Gunsmoke 30 The Simpsons 10 Will & Grace 14 Dallas 20 Law & Order 12 Murder, She Wrotethe file output_keys.txt should contain:
30: The Simpsons 20: Gunsmoke; Law & Order 14: Dallas 12: Murder, She Wrote 10: Will & Graceand the file output_titles.txt should contain:
Will & Grace The Simpsons Murder, She Wrote Law & Order Gunsmoke DallasNote: End each output file with a newline, and file1.txt is available to download.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 5 images