Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please work with Python Write program that first reads in the name of an input file and then reads the input file using the file.readlines()

Please work with Python

Write 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 TV shows with their corresponding number of seasons, followed by the corresponding rating of the show. Your program should put all the contents of the input file into a dictionary where the TV show name is the key, and the list of one integer and one float is the value. The integer represents the number of seasons the TV show has run and the float represents the rating of the show. Examine the input file that we provide and you will see that there is one show per line. You may use string methods and functions to separate what you want from each line, for example, the method split() is very useful for this project.

Sort the dictionary by key (least to greatest in alphabetical order) and output the results to a file named output_showNames.txt

For example, If the input file name is: tv_shows.txt and the content of it is:

Rizzoli and Isles,7,7.6

Supernatural,15,8.4

Vampire Diaries,8,7.7

2 Broke Girls,6,6.7

Simplify, I want move this txt.file to a dictionary, how to achieve it?

After that:

Next, put the number of seasons contained in the dictionary in a list and sort it in descending order (i.e. the maximum number of seasons goes first); put the ratings contained in the dictionary in a list and sort it in ascending order (i.e. the lowest rating goes first). Notice that to sort a list named seasons in descending order you can use the sorted method like this: sorted(seasons,reverse=True)

For the example above, the list of ordered seasons produced by your program should be [15,8,7,6] and the list of ordered ratings should be [6.7, 7.6, 7.7, 8.4]. You will use the two lists produced by your program to match each value in each of those lists to the tv shows that have those values in the seasons and the rating, respectively. So you will traverse the ordered list of numbers of seasons and then traverse the dictionary so that at each step you match the number of seasons with a TV show that has that number of seasons. Notice that there might be duplicate number of seasons, so you do not eliminate those duplicates but have to be careful when matching with the TV shows, that each show with the same number of seasons appears only once.

A similar procedure will be followed with the ordered list of ratings. The final result of this final step of Phase I are four (4) lists, one with the ordered number of seasons (possible duplicates), and one with the TV show names in that order. A third list with the ordered ratings and the fourth list with the TV show names in the order of the ratings.

Simplify said:

a. sort the seasons in descending order and match them to the tv shows, produce the two lists in the order of the seasons;

b. sort the ratings in ascending order and match them to the tv shows, produce the two lists in order of the ratings.

notice!!! please after sort the data, match them to tv shows, produce the two lists.

Thx.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

+3 What do you understand by a competitive positioning strategy?

Answered: 1 week ago