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
The output side of an ideal transformer has 35 turns, and supplies 2.0 A to a 24-W device. Ifthe input is a standard wall outlet
Crank

Answer:

The current drawn from the outlet is 0.2 A

The number of turns on the input side is 350 turns

Explanation:

Given;

number of turns of the secondary coil, Ns = 35 turns

the output current, I_s = 2 A

power supplied, P_s = 24 W

the standard wall outlet in most homes = 120 V = input voltage

For an ideal transformer; output power = input power

the current drawn from the outlet is calculated;

I_pV_p = P_s\\\\I_p = \frac{P_s}{V_p} = \frac{24}{120} = 0.2 \ A

The number of turns on the input side is calculated as;

\frac{N_p}{N_s} = \frac{I_s}{I_p}  \\\\N_p = \frac{N_sI_s}{I_p} \\\\N_p = \frac{35 \times 2}{0.2} \\\\N_p = 350 \ turns

4 0
3 years ago
When encountering low visibility from rain or fog, you should use your ____.
kirza4 [7]

Answer:

B

Explanation:

Low beams should only be used when fog and rain is present, as high beams can cause a dangerous glare to you and other drivers. You should also use your fog lights, but not every vehicle has them.

4 0
3 years ago
What is the thermal efficiency of this regeneration cycle in terms of enthalpies and fractions of total flow?
irga5000 [103]

Answer:

\eta =\dfrac{(h_3-h_4)-(h_2-h_1)}{(h_3-h_5)}

Explanation:

generally regeneration of cycle is used in the case of gas turbine. due to regeneration efficiency of turbine is increased but there is no effect on the on the net work out put of turbine.Actually in regeneration net heta input is decreases that is why total efficiency  increase.

 Now from T-S diagram

    W_{net}=W_{out}-W_{in}

   W_{net}=(h_3-h_4)-(h_2-h_1)

  Q_{in}=h_3-h_5

  Due to generation (h_5-h_2) amount of energy has been saved.

  Q_{generation}=Q_{saved}

So efficiency of cycle \eta =\frac{W_{net}}{Q_{in}}

  \eta =\dfrac{(h_3-h_4)-(h_2-h_1)}{(h_3-h_5)}

Effectiveness of re-generator

  \varepsilon =\dfrac{(h_5-h_2)}{(h_4-h_2)}

So the efficiency of regenerative cycle

\eta =\dfrac{(h_3-h_4)-(h_2-h_1)}{(h_3-h_5)}

7 0
3 years ago
16 . You are turning onto a two-lane road divided by a broken yellow line. You know immediately that:
Over [174]

When a person is turning onto a two-lane road divided by a broken yellow line, you know immediately that you are on a two-way road.

<h3>What is the road about?</h3>

Note that a Yellow centerlines can be seen in roads and it is one that is often used to separate traffic moving in different directions.

Note also that Broken lines can be crossed to allow slower-moving traffic and as such, When a person is turning onto a two-lane road divided by a broken yellow line, you know immediately that you are on a two-way road.

See full question below

You are turning onto a two-lane road divided by a broken yellow line. You know immediately that:

Answers

You are on a two-way road.

You are on a one-way road.

The road is under repair.

You must stay to the left of the broken yellow lines.

Learn more about  two-way road from

brainly.com/question/13123201

#SPJ2

5 0
2 years ago
After replacing a vacuum booster, the brakes lock up on a road test. Technician A says there is air trapped inside the brake lin
vitfil [10]

Answer:

Technician B

Explanation:

The brakes can lockup due to the following reasons

1) Overheating break systems

2) Use of wrong brake fluid

3) Broken or damaged drum brake backing plates, rotors, or calipers

4) A defective ABS part, or a defective parking mechanism or proportioning valve

5) Brake wheel cylinders, worn off

6) Misaligned power brake booster component

5 0
3 years ago
Other questions:
  • A high molecular weight hydrocarbon gas A is fed continuously into a heated mixed flow reactor (0.1liter) where it is thermally
    6·1 answer
  • Using the data from the table, what is P(3)?!
    9·1 answer
  • Complete the sentence to identify a useful advance in the culinary arts.
    8·1 answer
  • Based on the scenario, which type of engineering identifies Greg's role in Ethiopia?
    15·1 answer
  • Why are there few effective HCI standards?
    6·1 answer
  • Which outcome most accurately portrays the future for the timber company in the following scenario?
    9·1 answer
  • Please answer i dont understand and dont know the answer​
    14·1 answer
  • The minimum recommended standards for the operating system, processor, primary memory (RAM), and storage capacity for certain so
    12·2 answers
  • 1) Plastics that soften when heated,harden when cooled, and then can be heated and softened many times
    6·1 answer
  • The metric ruler is typically divided into
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!