Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To practice the concept of dictionary as a database Degree of Difficulty: Moderate. Before starting this question, first, download the data file CityData.txt from Canvas.

To practice the concept of dictionary as a database Degree of Difficulty: Moderate. Before starting this question, first, download the data file CityData.txt from Canvas. Make sure to put it in the same folder as your a6v1.py python code. Even though this assignment has 5 questions, your solutions to the 5 questions will be submitted in this one file. Write a function called read_citydata() that takes as parameter(s): a string indicating the name of a city data file This function should return a database (i.e. a dictionary-of-dictionaries) that stores all of the City data in a format that we will describe further below. You can review section 11.1.9 of the text for a refresher on what databases look like using dictionaries. Input File Format The data file for this question looks like this: Holiday Park,Ward 2,1,Spanish,English,French,Ukrainian,Cree,German North Park,Ward 1,2,Tagalog,Ukrainian,French,German,English Each line of the file contains all of the data for a single neighbourhood. The first item on the line is always the neighbourhoods name; names are guaranteed to be unique. The second item is always the name of a neighbourhoods ward, which in the 1st example above, is Ward 2. The third item is the number of schools in the neighbourhood. Following that are one or more languages which are spoken in that neighbourhood. For example, residents in Holiday Park can speak Spanish, English, French, Ukrainian, Cree, or German. Note that a language name CAN contain spaces. All of the data items on a line are separated by commas. Database Format Your function should open the file given as a parameter and read the data from it into a database (a dictionary of dictionaries). The keys for this database will be neighbourhood names, and the values will a record (i.e another dictionary) for that neighbourhood. The function read_citydata()should first create an empty dictionary to be the overall database. Then, as it reads the information for each neighbourhood from the input file, the function should create one record (i.e. one dictionary) with the following fields (you can choose alternative key values) The neighbourhoods name, as a string (key: Hood) The ward, as a string (key: Ward) The number of schools as an integer (key Schools) The languages spoken in the ward, as a list of strings (key :Lang) For example, the record (value part of key:value dictionary pair) for the 1st line in the file could be: { Hood : Holiday Park, Ward : Ward 2,Schools : 1, Lang : [Spanish, English, French, Ukrainian, Cree, German] } The record for each line of data read from the file should be added to the database using the neighbourhoods name as a key. Once all the records have been added, the function should

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Explain the main features of color vision.

Answered: 1 week ago

Question

Refer to Problem 10-1. What is the projects PI?

Answered: 1 week ago