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:

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter3: Performing Calculations With Formulas And Functions
Section: Chapter Questions
Problem 3.15CP
icon
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
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
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
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
JQuery and Javascript
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage