from collections import defaultdict filename = "tvshows.txt" # replace this with your filename #creating empty dictionary shows = defaultdict(list) #open the file file = open(filename) i = 1 for line in file: line = line.rstrip() #stripping over extra white spaces if i%6 == 1: title = line.upper() #movie titles as keys elif i%6 == 2: msg = line first_aired_code = int(msg[0:2]) first_aired = 0 if 0 <= first_aired_code <= 18: first_aired = 2000+ first_aired_code else: first_aired = 1900+ first_aired_code shows[title].append(first_aired) #appednig first aired year seasons = int(msg[2:4]) last_aired = first_aired + seasons shows[title].append(last_aired) # appending last aired year network = int(msg[4]) network_channel = "" if network == 1: network_channel = "ABC" elif network == 2: network_channel = "CBS" elif network == 3: network_channel = "NBC" elif network == 4: network_channel = "FOX" shows[title].append(network_channel) #appending network channel elif i%6 == 3 or i%6 == 4 or i%6 == 5 or i%6 == 0: shows[title].append(line) i+=1 #Printing the desired output for i in shows: print(i, "aired from", shows[i][0],"to",shows[i][1],"on", shows[i][2]+".") print("It starred",shows[i][3]+",",shows[i][4]+",",shows[i][5]+",","and",shows[i][6]+".") print() print() can space correctly thanks u

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

from collections import defaultdict
filename = "tvshows.txt"
# replace this with your filename
#creating empty dictionary
shows = defaultdict(list)
#open the file
file = open(filename)
i = 1
for line in file:
line = line.rstrip()
#stripping over extra white spaces
if i%6 == 1:
title = line.upper()
#movie titles as keys
elif i%6 == 2:
msg = line
first_aired_code = int(msg[0:2])
first_aired = 0
if 0 <= first_aired_code <= 18:
first_aired = 2000+ first_aired_code
else:
first_aired = 1900+ first_aired_code
shows[title].append(first_aired)
#appednig first aired year
seasons = int(msg[2:4])
last_aired = first_aired + seasons
shows[title].append(last_aired)
# appending last aired year
network = int(msg[4])
network_channel = ""
if network == 1:
network_channel = "ABC"
elif network == 2:
network_channel = "CBS"
elif network == 3:
network_channel = "NBC"
elif network == 4:
network_channel = "FOX"
shows[title].append(network_channel)
#appending network channel
elif i%6 == 3 or i%6 == 4 or i%6 == 5 or i%6 == 0:
shows[title].append(line)
i+=1
#Printing the desired output
for i in shows:
print(i, "aired from", shows[i][0],"to",shows[i][1],"on", shows[i][2]+".")
print("It starred",shows[i][3]+",",shows[i][4]+",",shows[i][5]+",","and",shows[i][6]+".")
print()
print()

can space correctly thanks u 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Dictionary
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY