Question: import copy # needed in examples of functions that modify input dict from typing import TextIO from constants import ( ID , HEADLINE, LISTED, FEATURES,

import copy # needed in examples of functions that modify input dict
from typing import TextIO
from constants import (ID, HEADLINE, LISTED, FEATURES, LOC, DESC, END, SEP,
LocType, ListingValueType, ListingType, BookSysType)
EXAMPLE_BOOK_SYS ={
'137': {
'identifier': '137',
'headline': 'Beautiful 4-bedroom home on lakeside',
'listed': '2024-07-17',
'features': ['4 bedroom', '3 bath', 'Pool'],
'location': ('New York', 'USA'),
'description': '''This is a beautiful 4-bedroom, 3-bath detached house
with an outdoor pool.'''},
'001': {
'identifier': '001',
'headline': 'House',
'listed': None,
'features': ['clean'],
'location': ('Hamilton', 'Canada'),
'description': None},
'05': {
'identifier': '05',
'headline': 'Stunning lakeside cottage',
'listed': '2021-02-08',
'features': [],
'location': ('Oxford','UK'),
'description': 'This is lakeside!'}
}
EXAMPLE_BY_COUNTRY ={
'USA': ['137'],
'Canada': ['001'],
'UK': ['05']
}
# We provide the header and docstring for this function to get you
# started and to demonstrate that there are no docstring examples in
# functions that read from files.
def read_book_sys_file(book_sys_file: TextIO)-> BookSysType:
"""Return a dict containing all booking system info in 'book_sys_file'.
Precondition: 'book_sys_file' is open for reading
'book_sys_file' is in the format described in the handout
"""
pass
# We provide the header and PART of a docstring for this function to
# get you started and to demonstrate the use of example data.
def make_country_to_listings(
book_sys: BookSysType)-> dict[str, list[str]]:
"""Return a dict that maps each country to a list of IDs of listings in
that country based on the information in booking system data 'book_sys'.
>>> make_country_to_listings(EXAMPLE_BOOK_SYS)== EXAMPLE_BY_COUNTRY
True
"""
pass
# We provide the header and PART of a docstring for this function to
# get you started and to demonstrate the use of function deepcopy in
# examples that modify input data.
def keep_complete_listings(book_sys: BookSysType)-> None:
"""Update the booking system data 'book_sys' so that it only contains
listings that are not missing any information.
>>> book_sys_copy = copy.deepcopy(EXAMPLE_BOOK_SYS)
>>> keep_complete_listings(book_sys_copy)
>>> book_sys_copy =={'137': EXAMPLE_BOOK_SYS['137']}
True
"""
pass
if __name__=='__main__':
import doctest
doctest.testmod()
# uncomment to test with example data files
# with open('example_data.txt') as example_data:
# RESULT = read_book_sys_file(example_data)
# print('Did we produce a correct dict? ', RESULT == EXAMPLE_BOOK_SYS)
# uncomment to work with a larger data set
# with open('data.txt') as data_txt:
# EXAMPLE = read_book_sys_file(data_txt)
# EXAMPLE_COUNTRY_TO_LISTING = make_country_to_listings(EXAMPLE)
# EXAMPLE_MOST_POPULAR_COUNTRIES = get_most_popular_countries(EXAMPLE)
# print(EXAMPLE_MOST_POPULAR_COUNTRIES)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!