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
Every two years or at recommendation by manufacturer.
9966 [12]

Answer:

Manufacturer’s Recommendations means the instructions, procedures, and recommendations which are issued by the manufacturer of any equipment used at the Facility relating to the operation, maintenance, or repair of such equipment, and any revisions or updates thereto from time to time issued by the manufacturer.

Manufacturer’s Recommendations means the instructions, procedures and recommendations which are issued by any manufacturer of the Equipment relating to the operation, maintenance and repair of the Equipment and any revisions to such instructions, procedures and recommendations agreed to by any manufacturer of the Equipment and which are valid at the time such operation, repair and maintenance is being carried out.

Manufacturer’s Recommendations means the written instructions, procedures and recommendations which are issued by the original equipment manufacturer of any plant or equipment used at the Utility Plant relating to the operation, maintenance and repair of such plant or equipment and any revisions thereto issued by the manufacturer, which are valid and applicable at the time such operation, maintenance or repair is undertaken. Notwithstanding the above, Manufacturer’s Recommendations shall not include any instructions, procedures or recommendations of a manufacturer of any plant or equipment that the Owner and the Operator have agreed in writing to exclude from this definition or have agreed in writing should not be followed.

Explanation:

4 0
2 years ago
is released from under a vertical gate into a 2-mwide lined rectangular channel. The gate opening is 50 cm, and the flow rate in
SVEN [57.7K]

Answer:

hello your question is incomplete attached below is the complete question

answer: There is a hydraulic jump

Explanation:

First we have to calculate the depth of flow downstream of the gate

y1 = C_{c} y_{g} ----------- ( 1 )

Cc ( concentration coefficient ) = 0.61  ( assumed )

Yg ( depth of gate opening ) = 0.5

hence equation 1 becomes

y1 = 0.61 * 0.5 = 0.305 m

calculate the flow per unit width q

q = Q / b ----------- ( 2 )

Q = 10 m^3 /s

 b = 2 m

hence equation 2 becomes

q = 10 / 2 = 5 m^2/s

next calculate the depth before hydraulic jump y2 by using the hydraulic equation

answer : where  y1 < y2 hence a hydraulic jump occurs in the lined channel

attached below is the remaining part of the solution

4 0
3 years ago
When passing another vehicle, when is it acceptable to drive over the
miss Akunina [59]

Answer:

Under no circumstances

Explanation:

I'm not 100% sure why, but I remember hearing that you're not suposed to go over the speed limit no matter what

7 0
3 years ago
Read 2 more answers
(a) For a given material, would you expect the surface energy to be greater than, the same as, or less than the grain boundary e
aksik [14]

Answer:

(a) Surface energy is greater than grain boundary energy due to the fact that the bonds of the atoms on the surface are lower than those of the atoms at the grain boundary. The energy is also directly proportional to the number of bonds created.

(b) The energy of a high-angle grain boundary is higher than that of a small-angle grain boundary because the high-angle grain boundary has a higher misalignment and smaller number of bonds than a small-angle grain boundary.

Explanation:

(a) Surface energy is greater than grain boundary energy due to the fact that the bonds of the atoms on the surface are lower than those of the atoms at the grain boundary. The energy is also directly proportional to the number of bonds created.

(b) The energy of a high-angle grain boundary is higher than that of a small-angle grain boundary because the high-angle grain boundary has a higher misalignment and smaller number of bonds than a small-angle grain boundary.

5 0
2 years ago
A(n) ____ is an object setting used to control the visible display of objects.
KatRina [158]
Remote?? maybe I’m not really sure
3 0
3 years ago
Other questions:
  • Mike is involved in developing the model building codes that various states and local authorities in the United States adopt. He
    6·1 answer
  • Memory Question!
    7·1 answer
  • A centrifugal pump is required to pump water to an open water link situated 4 km away from the location of the pump through a pi
    8·1 answer
  • Consider an area-source box model for air pollution above a peninsula of land. The length of the box is 15 km, its width is 80 k
    8·1 answer
  • Ignore swell and shrinkage for this problem.
    5·1 answer
  • An aluminum bar 125 mm long with a square cross section 16 mm on an edge is pulled in tension with a load of 66,700 N and experi
    14·1 answer
  • prove that the heat transfer at the constant pressure is given by the enthalpy change during the process​
    7·1 answer
  • A cross beam in a highway bridge experiences a stress of 14 ksi due to the dead weight of the bridge structure. When a fully loa
    14·1 answer
  • What speeds did john j montgomerys gliders reach
    12·1 answer
  • Ethylene glycol, the ingredient in antifreeze, does not cause health problems because it is a clear liquid.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!