Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 2 . 1 0 LAB: Sorting TV Shows ( dictionaries and lists ) Write a program that first reads in the name of an
LAB: Sorting TV Shows dictionaries and lists
Write a program that first reads in the name of an input file and then reads the input file using the file.readlines method. The input file contains an unsorted list of number of seasons followed by the corresponding TV show. Your program should put the contents of the input file into a dictionary where the number of seasons are the keys, and a list of TV shows are the values since multiple shows could have the same number of seasons
Sort the dictionary by key greatest to least and output the results to a file named outputkeys.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 outputtitles.txt
Ex: If the input is:
filetxt
and the contents of filetxt are:
Gunsmoke
The Simpsons
Will & Grace
Dallas
Law & Order
Murder, She Wrote
the file outputkeys.txt should contain:
: The Simpsons
: Gunsmoke; Law & Order
: Dallas
: Murder, She Wrote
: Will & Grace
and the file outputtitles.txt should contain:
Will & Grace
The Simpsons
Murder, She Wrote
Law & Order
Gunsmoke
Dallas
Note: End each output file with a newline, and filetxt is available to download.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started