ef read_airports(airports_source: TextIO) -> AirportsDict: """Return a dictionary containing the information in airports_source. The dictionary maps IATA airport codes to a sub-dictionary containing information about that airport. Any entries that have a null IATA code in airports_source should NOT be included in this dictionary. The sub-dictionaries containing information about each airport have str keys that identify the information category (these keys come from the categories in the header line in airports_source), and the value is the respective data for that airport, for that category, as given in airports_source. Precondition: - Every IATA airport code in the data is unique - The data in airports_source is formatted correctly
def read_airports(airports_source: TextIO) -> AirportsDict:
"""Return a dictionary containing the information in airports_source.
The dictionary maps IATA airport codes to a sub-dictionary containing
information about that airport.
Any entries that have a null IATA code in airports_source should NOT be
included in this dictionary.
The sub-dictionaries containing information about each airport have str keys
that identify the information category (these keys come from the categories
in the header line in airports_source), and the value is the respective
data for that airport, for that category, as given in airports_source.
Precondition:
- Every IATA airport code in the data is unique
- The data in airports_source is formatted correctly
>>> example_airport_file = flight_example_data.create_airport_file()
>>> airports_res = read_airports(example_airport_file)
>>> airports_res['AA1']['Airport ID'], airports_res['AA1']['Name']
('1', 'Apt1')
>>> airports_res['AA4']['Airport ID'], airports_res['AA4']['Name']
('4', 'Apt4')
>>> len(airports_res)
4
>>> airports_res == flight_example_data.create_example_airports()
True
"""
Trending now
This is a popular solution!
Step by step
Solved in 2 steps