1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
wlad13 [49]
3 years ago
3

PYTHONSorting 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 (least to greatest) and output the results to a file named output_keys.txt, separating multiple TV shows associated with the same key with a semicolon (;). Next, sort the dictionary by values (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:20Gunsmoke30The Simpsons10Will & Grace14Dallas20Law & Order12Murder, She Wrotethe file output_keys.txt should contain:10: Will & Grace12: Murder, She Wrote14: Dallas20: Gunsmoke; Law & Order30: The Simpsonsand the file output_titles.txt should contain:DallasGunsmokeLaw & OrderMurder, She WroteThe SimpsonsWill & Grace
Computers and Technology
1 answer:
3241004551 [841]3 years ago
3 0

Answer:

with open("file1.txt", "r") as file:

lines = file.readlines()

mydict = dict()

for x in range(0, len(lines) - 1, 2):

mydict[lines[x]] = lines[x-1]

dict_keys = sorted(mydict.keys)

sorted_dict ={}

for key in dict_keys:

sorted_dict[key] = mydict[key]

with open("output_keys.txt", "a+") as writn:

for key, value in sorted_dict.items():

writn.write(key: value)

writn.write("\n")

dict_values = sorted(mydict.values)

with open("output_titles", "a+") as title:

for name in dict_values:

title.write(name)

title.write("\n")

Explanation:

The python program above reads in the file context, files.txt, and creates a dictionary of the file with the number of seasons as the key and movie title as the value. The sorted dictionary is saved in the output_keys.txt file and the titles in output_titles.txt file.

You might be interested in
____ refers to driving around an area with a Wi-Fi-enabled device to find a Wi-Fi network in order to access and use it without
777dan777 [17]

 Answer:War driving

Explanation: War driving is the activity which is done for searching for the Wi-Fi connection while driving vehicle .The main purpose of the war driving is gaining and accessing the network of Wi-Fi by being in slowly moving vehicle. The act is carried out by the individual or more people.

Other options are incorrect because Wifi driving and Wifi finding are not technical words in the computer field and E-stalking is the stacking activity with the help of internet enables electronic devices.Thus, the correct option is war driving.

7 0
3 years ago
Read 2 more answers
What is the output of the following code? public class Test { public static void main(String[] args) { int list[] = {1, 2, 3, 4,
lyudmila [28]

Answer:

1 1 1 1 1 1

Explanation:

You copy the first location to the second, and then the second to the third, and so on. Effectively the value of the first location (1) is copied to all locations.

6 0
3 years ago
Which component comprises the central processing unit?
lbvjy [14]
I believe it is Control unit..
Hope this helps!
3 0
4 years ago
The third step of the SDLC has 3 phases, specifically, developing several system proposals, selecting the most feasible proposal
KIM [24]

Answer:

Software requirement and estimation.

Explanation:

In this step, the proposals are collected, and best from them is made, and then checked for feasibility, and the SRS document is formulated finally. Now the each developer, designers, writers are being assigned the task, then finally the development phase starts. However, since this is SDLC, you will not find any iteration, and the defects are checked only after testing which is the last phase. And a lot of errors remain even after delivery sometimes. Also, it is time consuming to edit the errors in this manner. Hence, agile methodology is preferred.

6 0
3 years ago
How do I give Brainliest? Will give brainliest when I figure out how
Lina20 [59]
When somebody writes the answer for your question and posts it on your question it will show a “(crown)mark as brainliest” in blue. click it and it’ll turn yellow and mark the person the brainliest for your question
7 0
3 years ago
Read 2 more answers
Other questions:
  • An engineer is assigned the task of reducing the air pollutants being released from a power plant that generates electricity by
    9·1 answer
  • 1. Why isn't solar energy usually the only power source for a region?
    10·2 answers
  • How do you put sound/music in Google classroom slideshow?
    15·1 answer
  • Charlie does not think he will be able to finish this project by the deadline at this point in the decision making process to so
    8·1 answer
  • Consider the following process for generating binaries. A compiler is used to generate the object code for individual modules, a
    8·1 answer
  • The _____ feature will mark all changes made to a document for others to review at a later time.
    13·1 answer
  • Coding question. Please help me?
    7·1 answer
  • Which best compares portrait and landscape orientations?
    7·1 answer
  • How does the technology affect you daily living? Give situations where you use technology and how it helped you.​
    5·1 answer
  • If you delete search results, you will a. clear the history on the computer. b. delete files from our computer. c. modify the re
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!