def read_flights(flights_source: TextIO, routes: RouteDict) -> FlightDir: """Return the flights from flights_source, including only the ones that have an entry in routes. >>> from io import StringIO >>> flight_src = StringIO(TEST_FLIGHTS_SRC) >>> actual = read_flights(flight_src, TEST_ROUTES_DICT_FOUR_CITIES) >>> actual == TEST_FLIGHTS_DIR_FOUR_CITIES True """ flights = [] src_index = FLIGHT_DATA_INDEXES["Source airport"] dst_index = FLIGHT_DATA_INDEXES["Destination airport"] # Complete this function. for line in routes_source:
def read_flights(flights_source: TextIO, routes: RouteDict) -> FlightDir: """Return the flights from flights_source, including only the ones that have an entry in routes. >>> from io import StringIO >>> flight_src = StringIO(TEST_FLIGHTS_SRC) >>> actual = read_flights(flight_src, TEST_ROUTES_DICT_FOUR_CITIES) >>> actual == TEST_FLIGHTS_DIR_FOUR_CITIES True """ flights = [] src_index = FLIGHT_DATA_INDEXES["Source airport"] dst_index = FLIGHT_DATA_INDEXES["Destination airport"] # Complete this function. for line in routes_source:
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
def read_flights(flights_source: TextIO, routes: RouteDict) -> FlightDir:
"""Return the flights from flights_source, including only the ones
that have an entry in routes.
>>> from io import StringIO
>>> flight_src = StringIO(TEST_FLIGHTS_SRC)
>>> actual = read_flights(flight_src, TEST_ROUTES_DICT_FOUR_CITIES)
>>> actual == TEST_FLIGHTS_DIR_FOUR_CITIES
True
"""
flights = []
src_index = FLIGHT_DATA_INDEXES["Source airport"]
dst_index = FLIGHT_DATA_INDEXES["Destination airport"]
# Complete this function.
for line in routes_source:
![def read_routes (routes_source: TextI0, airports: Airport Dict) -> RouteDict:
"""Return the flight routes from routes_source, including only the ones
that have an entry in airports. If there are multiple routes between
routes_source and a destination (on different airlines for example),
include the destination only once. Routes that include null airport IDs
should still be included, but routes that have empty IATA should be
excluded.
>>> from io import StringI0
>>> routes_src = StringIO (TEST_ROUTES_SRC)
>>> actual = read_routes (routes_src, TEST AIRPORTS_DICT)
>>> actual == TEST_ROUTES_DICT_FOUR_CITIES
True
||||||
routes = {}
src_index = ROUTE_DATA_INDEXES ["Source airport"]
dst_index = ROUTE_DATA_INDEXES ["Destination airport"]
# Complete this function.
# Note that each value in the resulting dictionary is a set of IATA codes
for line in routes_source:
cols=line.strip().split(",")
src_iata=cols [src_index].strip()
dst_iata=cols [dst_index].strip()
if src_iata in airports and dst_iata in airports and dst_iata not in
if src_iata not in routes:
routes [src_iata] = []
routes [src_iata].append(dst_iata)
return routes](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F99722726-db42-4938-b031-e662dbbc7dd1%2Fb484ec8f-e95b-468e-a531-279928fb4bfc%2Fo45bf7_processed.png&w=3840&q=75)
Transcribed Image Text:def read_routes (routes_source: TextI0, airports: Airport Dict) -> RouteDict:
"""Return the flight routes from routes_source, including only the ones
that have an entry in airports. If there are multiple routes between
routes_source and a destination (on different airlines for example),
include the destination only once. Routes that include null airport IDs
should still be included, but routes that have empty IATA should be
excluded.
>>> from io import StringI0
>>> routes_src = StringIO (TEST_ROUTES_SRC)
>>> actual = read_routes (routes_src, TEST AIRPORTS_DICT)
>>> actual == TEST_ROUTES_DICT_FOUR_CITIES
True
||||||
routes = {}
src_index = ROUTE_DATA_INDEXES ["Source airport"]
dst_index = ROUTE_DATA_INDEXES ["Destination airport"]
# Complete this function.
# Note that each value in the resulting dictionary is a set of IATA codes
for line in routes_source:
cols=line.strip().split(",")
src_iata=cols [src_index].strip()
dst_iata=cols [dst_index].strip()
if src_iata in airports and dst_iata in airports and dst_iata not in
if src_iata not in routes:
routes [src_iata] = []
routes [src_iata].append(dst_iata)
return routes
![def read_routes (routes_source: TextI0, airports: Airport Dict) -> RouteDict:
"""Return the flight routes from routes_source, including only the ones
that have an entry in airports. If there are multiple routes between
routes_source and a destination (on different airlines for example),
include the destination only once. Routes that include null airport IDs
should still be included, but routes that have empty IATA should be
excluded.
>>> from io import StringI0
>>> routes_src = StringIO (TEST_ROUTES_SRC)
>>> actual = read_routes (routes_src, TEST AIRPORTS_DICT)
>>> actual == TEST_ROUTES_DICT_FOUR_CITIES
True
||||||
routes = {}
src_index = ROUTE_DATA_INDEXES ["Source airport"]
dst_index = ROUTE_DATA_INDEXES ["Destination airport"]
# Complete this function.
# Note that each value in the resulting dictionary is a set of IATA codes
for line in routes_source:
cols=line.strip().split(",")
src_iata=cols [src_index].strip()
dst_iata=cols [dst_index].strip()
if src_iata in airports and dst_iata in airports and dst_iata not in
if src_iata not in routes:
routes [src_iata] = []
routes [src_iata].append(dst_iata)
return routes](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F99722726-db42-4938-b031-e662dbbc7dd1%2Fb484ec8f-e95b-468e-a531-279928fb4bfc%2Fllcyzg_processed.png&w=3840&q=75)
Transcribed Image Text:def read_routes (routes_source: TextI0, airports: Airport Dict) -> RouteDict:
"""Return the flight routes from routes_source, including only the ones
that have an entry in airports. If there are multiple routes between
routes_source and a destination (on different airlines for example),
include the destination only once. Routes that include null airport IDs
should still be included, but routes that have empty IATA should be
excluded.
>>> from io import StringI0
>>> routes_src = StringIO (TEST_ROUTES_SRC)
>>> actual = read_routes (routes_src, TEST AIRPORTS_DICT)
>>> actual == TEST_ROUTES_DICT_FOUR_CITIES
True
||||||
routes = {}
src_index = ROUTE_DATA_INDEXES ["Source airport"]
dst_index = ROUTE_DATA_INDEXES ["Destination airport"]
# Complete this function.
# Note that each value in the resulting dictionary is a set of IATA codes
for line in routes_source:
cols=line.strip().split(",")
src_iata=cols [src_index].strip()
dst_iata=cols [dst_index].strip()
if src_iata in airports and dst_iata in airports and dst_iata not in
if src_iata not in routes:
routes [src_iata] = []
routes [src_iata].append(dst_iata)
return routes
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education