Write a program that first reads in the name of an input file and then reads...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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: filel.txt and the contents of file1.txt are: 20 Gunsmoke 30 The Simpsons 10 Will & Grace 14 and the contents of file1.txt are: 20 Gunsmoke 30 The Simpsons 10 Will & Grace. 14 Dallas 20 Law & Order 12 Murder, She Wrote the file output_keys.txt should contain: 10: Will & Grace 12: Murder, She Wrote 14: Dallas 20: Gunsmoke; Law & Order 30: The Simpsons and the file output_titles.txt should contain: Dallas Gunsmoke 12: Murder, She Wrote 14: Dallas 20: Gunsmoke; Law & Order 30: The Simpsons and the file output_titles.txt should contain: Dallas Gunsmoke Law & Order Murder, She Wrote The Simpsons Will & Grace 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 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: filel.txt and the contents of file1.txt are: 20 Gunsmoke 30 The Simpsons 10 Will & Grace 14 and the contents of file1.txt are: 20 Gunsmoke 30 The Simpsons 10 Will & Grace. 14 Dallas 20 Law & Order 12 Murder, She Wrote the file output_keys.txt should contain: 10: Will & Grace 12: Murder, She Wrote 14: Dallas 20: Gunsmoke; Law & Order 30: The Simpsons and the file output_titles.txt should contain: Dallas Gunsmoke 12: Murder, She Wrote 14: Dallas 20: Gunsmoke; Law & Order 30: The Simpsons and the file output_titles.txt should contain: Dallas Gunsmoke Law & Order Murder, She Wrote The Simpsons Will & Grace
Expert Answer:
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Fergie has the choice between investing in a State of New York bond at 11.2 percent and a Surething Incorporated bond at 14.2 percent. Assuming that both bonds have the same nontax characteristics...
-
In this project, we will write a program that controls a quiz show, much like the many popular TV shows. The program will read in a group of questions and their multiple choice answers, storing them...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The three courses below represent a polygon. They are consecutive azimuths measured clockwise from North in DMS. Course A to B: 55-35-21 Course B to C: 175-48-19 Course C to A: 293-22-28 Choose the...
-
Depletion and DepreciationMining Khamsah Mining Company has purchased a tract of mineral land for $900,000. It is estimated that this tract will yield 120,000 tons of ore with sufficient mineral...
-
A choir director must select six hymns for a Sunday church service. She has three hymn books, each containing 25 hymns (there are 75 different hymns in all). In how many ways can she select the hymns...
-
Fiona lost her pet dog and told Mary, If you find my dog and return him to me, Ill pay you \($200.\) Mary said nothing in response but found the dog and returned him. Fiona refused to pay because...
-
The common stock of Moes Restaurant is currently selling for $80 per share has a book value of $60 per share, and there are 1 million shares of common stock outstanding. In addition, the firm also...
-
7. 8. The work done by a gas molecule in an isolated system is given by W=ae KT, where x is the displacement, k is the Boltzmann constant and T is the temperature. and are constants. Then the...
-
The Case Study - "Lemonade: Delighting Insurance Customers with AI and Behavioral Economics". 1. How do you explain the phenomenal growth experienced by Lemonade? 2. Does Lemonade create a unique...
-
If a natural gas has a specific gravity of 0.60 relative to air at 14.70-psi-abs and 68 degrees Fahrenheit. a. Calculate the density of gas at constant pressure and temperature b. Determine its...
-
This extract describes changes in the UK company Bunzl, which announced at the start of 2005 that it would sell Filtrona, a business making cigarette filters, and concentrate on its outsourcing...
-
Explain what is meant by the accrual of liabilities.
-
Describe the main contents of a business plan for presenting to a bank providing finance for a small business.
-
Register for the free version of Talkwalker. Do a search for the brand you chose in activity 1, and view the time line of engagement. What new insights have you learned about the brand? Data From...
-
How is the economic order quantity calculated.
-
What is an engram? a. emotional focus of a memory from aparticularly meaningful event b. mental trauma that creates adistorted memory that is full of errors c. a group of neurons thatserves as...
-
Two mutually exclusive investment alternatives are being considered. Alternative A requires an initial investment of $20,000 in a machine. Annual operating and maintenance costs are anticipated to be...
-
Write the following method that returns the maximum value in an ArrayList of integers. The method returns null if the list is null or the list size is 0. public static Integer max(ArrayList list)...
-
Write a program that prompts the user to enter two strings and tests whether the second string is a substring of the first string. Suppose the neighboring characters in the string are distinct....
-
Rewrite Listing 5.1 RepeatAdditionQuiz.java to alert the user if an answer is entered again. Hint: use an array list to store answers. Here is a sample run: Listing What is 5 + 9? 12 Wrong answer....
-
a. Show that the mean-squared forecast error \(E\left[\left(\hat{y}_{T+1}-y_{T+1} ight)^{2} \mid I_{T} ight]\) for a forecast \(\hat{y}_{T+1}\), that depends only on past information \(I_{T}\), can...
-
Consider the AR(1) model \(y_{t}=\delta+\theta y_{t-1}+e_{t}\) where \(|\theta|)=0\) and \(\operatorname{var}\left(e_{t} \mid I_{t-1} ight)=\sigma^{2}\). Let \(\bar{y}_{-1}=\sum_{t=2}^{T} y_{t}...
-
Consider a stationary model that combines the \(\operatorname{AR}(2)\) model \(y_{t}=\delta+\theta_{1} y_{t-1}+\theta_{2} y_{t-2}+e_{t}\) with an \(\mathrm{AR}(1)\) error model \(e_{t}=ho...
Study smarter with the SolutionInn App