
Please follow the following Python code to complete this exercise:
"""
PROGRAMMING ASSIGNMENT 07
Filename: 'exercise1.py'
"""
# Place your imports here if any
def build_attraction_dict(filename):
"""
Read from the file for which the filename was given and returns a dictionary
The key / value pairs in the dictionary will be:
• key → attraction name (str type)
• value → Province (str type)
"""
# TODO
def add_attraction(dic):
"""
This function takes a dictionary as a parameter and does not return anything.
The function:
• asks the user to input an attraction name
• asks the user to input a province
• updates the dictionary with a new key / value pair (with a similar format for
task 1)
"""
# TODO
def build_province_attraction_dict(dic):
"""
This function takes a dictionary as a parameter and returns another dictionary.
The input dictionary is constituted of key / value pairs similar to the ones built in task 1.
The returned dictionary should have key / value pair with:
• key → Province (str type)
• value → list of attraction names (list of str type) associated to the Province
"""
# TODO
def most_attractions(dic):
"""
This function takes a dictionary as a parameter and returns a set.
The input dictionary is constituted of key / value pairs similar to the ones built in task 3.
The returned set should contain the Provinces which have at least 3 tourist attractions
(in the input dictionary).
"""
# TODO
def main():
"""
The main() function will
1. calls `build_province_attraction_dict` with filename top_tourist_attractions.txt as
parameter to generate the first dictionary.
2. calls `add_attraction` one time in order to update the dictionary. The user will input
a new (non-existing) attraction name/Province pair.
3. calls `build_province_attraction_dict` in order to generate a second dictionary.
4. calls `most_attractions` in order to generate the set of Provinces with at least 3 attractions.
5. prints the Provinces with at least 3 attractions. Display one Province per line.
See sample examples for the proper format (empty line + Header line).
"""
# TODO
if __name__ == '__main__':
main()
Below is the top_tourist_attractions.txt:
Yunnan,Three Pagodas
Hunan,Zhangjiajie National Forest Park
Yunnan,Shilin Stone Forest
Yunnan,Lijiang Old Town
Hubei,Wudang Mountains
Jiangsu,Zhouzhuang
Shandong,Mount Tai
Yunnan,Tiger Leaping Gorge
Jiangsu,Suzhou Gardens & Canals
Shaanxi,Xi an City Walls
Gansu,Mogao Caves
Guangxi,Longji Terraces
Beijing,Summer Palace
Shanxi,Hanging Monastery
Guangxi,Reed Flute Cave
Shanxi,Yungang Grottoes
Zhejiang,West Lake
Sichuan,Jiuzhai Valley
Henan,Longmen Grottoes
Shanghai,Pudong Skyline
Yunnan,Hani Terraces
Sichuan,Leshan Giant Buddha
Anhui,Yellow Mountain
Guangxi,Li River Cruise
Shaanxi,Terracotta Army
Hongkong,Victoria Harbour
Beijing,Forbidden City
Xizang,Potala Palace



Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 3 images

- python pleasearrow_forwardThis code is supposed to be done on Python.arrow_forwardFirst programming homework Create a class of records for a gradebook called Rec. The data should be private, and should include a firstname, lastname, array of three grades, and a field for average grade. Build two constructors: a default constructor and a constructor that takes the first and last name. Build a function to read the data, either from a file or from cin. The read function reads the two names and three grades, but does not read the average grade. Build a write function that writes the data either to a file or to cout. The write function prints all of the data on one line with spaces between fields. Build a function to calculate the average grade field. Build an overloaded operator == to compare two records. This should be implemented as a friend function. Declare the constructors and functions in the body of the class, but implement them outside the class. I will provide you with a driver called hw1.cpp in ~cthorpe/public/142 and with a test file HW1.txt in the same…arrow_forward
- Python code please help, indentation would be greatly appreciatedarrow_forward3. form_letter This function takes a list of dictionaries, where each dictionary has an entry of key "name" and entry of key "date". It returns a list of strings, where each output string has replaced the name and the date into the following template. Use the format method on strings -- see Lecture 8! The template should be exactly like this -- just copy-paste this into your code. TEMPLATE = """Dear {name},Your appointment is at {time}.Thanks very much.-- bimmy""" It can be either local to your function, or global in your Python file. Your choice! Sample calls should look like this. >>> form_letter([{"name":"Alex", "time":"three o'clock"},{"name":"Laura", "time":"the stroke of midnight"}])["Dear Alex,\nYour appointment is at three o'clock.\nThanks very much.\n-- bimmy", 'Dear Laura,\nYour appointment is at the stroke of midnight.\nThanks very much.\n-- bimmy']arrow_forwardq2arrow_forward
- JS Write a function named number_of_pairs whose parameter is an object/dictionary with strings as keys and integers as values. Your function should returns the number of key-value pairs in the parameter.arrow_forwardpython exercise: Write a Python function called get_top_students that takes the list of dictionaries as input and returns a dictionary containing the name and GPA of the top two students in the list. Each dictionary has the following keys: "name", "age", "major", and "gpa".arrow_forwardAssume a Dictionary structure has been defined that associates letter grades to their respective integer "quality point" values used for calculating a student's grade point average. The name of the structure is gradePoints. Write a statement to retrieve the quality point value for a letter grade of "C". Store the retrieved value in a variable named "qPoints".arrow_forward
- 13. While dictionaries are designed so that we can find a value based on a key, every so often we need to perform a reverse lookup. For example, imagine a dictionary where the keys are names and the values are phone numbers. Usually we want to find the phone number based on the name, but occasionally you might need to find a name based on the phone number. Write a function called reverse_lookup(dictionary, value) that returns all the keys in the dictionary associated with the specified value. Note: In dictionaries, the keys are guaranteed to be unique, but the values are not. So your function should return a list containing all of the matching keys (if any) Example: Given this dictionary, groups = {'Apple': 'Fruit', 'Spinach': 'Vegetable', 'Banana': 'Fruit'} reverse_lookup (groups. Vegetable') ["Spinach'] reverse_lookup (groups, Fruit') ['Apple'. 'Banana'] reverse_lookup (groups. 'Meat') []arrow_forwardIn python make a function with the parameter of a dict[str, str] the function will simply invert the dictionary do not use .get, .item, .values, or import builtins If you encounter more than one of the same key when trying to invert the key and value, raise a keyerror for example ['john': 'white', 'garcia': 'white'], should trigger the raise KeyError callarrow_forwardDescription You are provided a skeleton code in the file student_code.c. Some functions are completely implemented, and some are partially implemented. Additionally, you can add your own functions if required. Complete the program as per following details so that we can have functionality as described in the Synopsis above. All the code in single C file. REMEMBER DO NOT USE sleep(). 1. The given code reads the file's content for you and populates a dynamic array of type struct thread with information about the threads. The threads have filled in this list of threads for you. Additionally, you can check the threadCount variable to see how many threads were created using the input file. If more members are needed, you can add them. You might be able to initialise those extra members during file read if you wish to. 2. The main() already contains the code to read threads from input file. However, there is no code to initialize, execute and synchronize threads. You have to perform these…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





