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
Andreyy89
3 years ago
6

9.21 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 (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:
Engineering
1 answer:
natka813 [3]3 years ago
8 0

The following code or the program will be used

<u>Explanation:</u>

def readFile(filename):

   dict = {}

   with open(filename, 'r') as infile:

       lines = infile.readlines()

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

           if lines[index].strip()=='':continue

           count = int(lines[index].strip())

           name = lines[index + 1].strip()

           if count in dict.keys():

               name_list = dict.get(count)

               name_list.append(name)

               name_list.sort()

           else:

               dict[count] = [name]

           print(count,name)

   return dict

def output_keys(dict, filename):

   with open(filename,'w+') as outfile:

       for key in sorted(dict.keys()):

           outfile.write('{}: {}\n'.format(key,';'.join(dict.get(key))))

           print('{}: {}\n'.format(key,';'.join(dict.get(key))))  

def output_titles(dict, filename):

   titles = []

   for title in dict.values():

       titles.extend(title)

   with open(filename,'w+') as outfile:

       for title in sorted(titles):

           outfile.write('{}\n'.format(title))

           print(title)

def main():

   filename = input('Enter input file name: ')

   dict = readFile(filename)

   if dict is None:

       print('Error: Invalid file name provided: {}'.format(filename))

       return

   print(dict)

   output_filename_1 ='output_keys.txt'

   output_filename_2 ='output_titles.txt'

   output_keys(dict,output_filename_1)

   output_titles(dict,output_filename_2)  

main()

You might be interested in
A plane, opaque, surface M has the following properties: gray, diffuse, absorptivity = 0.7, surface area = 0.5 m2 , temperature
BaLLatris [955]

Answer:

The rate of energy absorbed per unit time is 3500W.

Explanation:

From the question, we were given the following parameters;

Plane, opaque, gray, diffuse surface

â = 0.7

Surface area, A = 0.5m²

Incoming radiant energy, G = 10000w/m²

T = 500°C

Rate of energy absorbed is âAG;

âAG = 0.7 × 0.5 × 10000

âAG = 3500W.

The energy absorbed is measured in watts and denoted by the symbol W.

7 0
4 years ago
Which of the following lists the steps of a process in the correct order?
Vladimir79 [104]

Answer: C. Problem identification, solution design, implementation, evaluation.

Explanation:

4 0
3 years ago
Read 2 more answers
What are the major steps in manufacturing biofuels from biomass?
TiliK225 [7]

Answer:

Pyrolysis

It is a biomass in anaerobic conditions results in the production of solid charcoal, liquid bio-oil and fuel gases. . Pyroolysis can be categorized into three groups depending on environment conditions, namely conventional pyrolysis, fast pyrolysis and flash pyrolysis.

5 0
3 years ago
The concentration of carbon monoxide (co) in an exhaust gas is 1x10^4 ppmv. what is the concentration in mg/m^3 at 25 and 1 atm
Mrrafil [7]

Answer:

1.1451 x 104 (11451.13)mg/m3

Explanation:

1 ppmv is defined as one volume of a contaminant or solid(CO)(mL) in 1 x 106 volume of solvent/water.

1ppmv = 1mL/m3

Concentration in mg/m3 = volume in ppm x molecular weight x pressure(kPa)/( gas constant x temperature(K)

Molecular weight of CO = 12 + 16

= 28g/mol

Temperature = 273.15 + 25

= 298.15K

Pressure = 1 x 101.325kPa

= 101.325kPa

Ppmv = 1 x 10-4ppmv

Gas constant, R = 8.3144 L.kPa/mol.K

Concentration in mg/m3 = (1 x 104 * 28 * 101.325)/(8.3144 * 298)

= 1.1451 x 104mg/m3

= 11451.13 mg/m3

3 0
4 years ago
Explain all the characteristics of computer<br>​
Sedaia [141]
They are as follows-

Speed
Accuracy
Storage
Versatility
Diligence
Automation
Reliability
Power of Remembering

Let us understand each characteristic in brief:-

Speed – Speed of a computer means the time it takes to complete any given task. The computer works at a very lightning speed. For example, a computer takes a second to calculate 3 million calculations rather than a human which takes years. Hence nowadays the speed of the computer is measured in terms of microseconds, Nanoseconds, and even in Pico seconds instead of seconds or milliseconds.


Accuracy – The computers are programmed and designed in such a manner that their results are almost 100% accurate. It performs all the tasks with the same accuracy. There are very few chances of uncertainty in results and even though an error occurs, it can happen either due to wrong input data or unreliable programs by a programmer. Such errors are referred to as Garbage In Garbage Out (GIGO) which means, if you provide wrong instructions to the computer then you get wrong results.


Versatility – Along with being accurate and diligent a computer is also a versatile device. It can perform several types of tasks at a time if they are reduced to a certain set of logical steps. A computer can be used for many purposes at different places such as booking air and rail tickets, weather forecasting, listening to music, and playing games. Also at a time, one can pay his utility bills and can make a monthly budget too. It can prepare documents, data sheets and also can make models of houses, dams, etc.
Diligence – The ability of a computer to perform tasks without getting tired is known as diligence. Computers are highly reliable, they do not get fed up, exhausted, or lack concentration. They can work for hours and hours unlike humans and can give accurate or error-free results. For example, humans will start feeling tired after 2 -3 hours and will lack concentration whereas a computer will keep on working until the results are achieved.
Automation – Automation means working automatically. A computer can work on its own without the intervention of the person using it. Programs can be made for the computer to perform the task and based on the sequence it executes the tasks and gives accurate results. In case an error occurs, it gives error messages too and registers the logs.
Reliability – High reliability of a computer depends on low failure rate and easy maintenance. The results given out by the computer are reliable as the accuracy is almost 100%.
Power of Remembering – The computer has the power of storing data or information for several years. It cannot lose the data on its own. A person can retrieve the data whenever required and the data remains the same after a number of years also. It gives the freedom to the user to decide on how much data to store and how much to remove.
5 0
3 years ago
Other questions:
  • A commercial refrigerator with refrigerant -134a as the working fluid is used to keep the refrigerated space at -30C by rejectin
    10·3 answers
  • A horizontal, opaque surface at a steady-state temperature of 80°C is exposed to an airflow having a free stream temperature of
    7·1 answer
  • Give four effects of water hammer.​
    6·1 answer
  • As shown, a load of mass 10 kg is situated on a piston of diameter D1 = 140 mm. The piston rides on a reservoir of oil of depth
    9·1 answer
  • If my friend have the corona what do I do
    11·2 answers
  • Practice finding the volume of a sphere.
    10·2 answers
  • (35-39) A student travels on a school bus in the middle of winter from home to school. The school bus temperature is 68.0° F. Th
    13·1 answer
  • A city is experiencing a windstorm. The wind has blown away some of the houses in that city. What load bearing factor did the ar
    14·1 answer
  • If an object has the same number of positive and negative charges, its electrical charge is
    12·1 answer
  • Dust, dirt, or metal chips can pose a potential ____ injury risk in a shop.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!