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

 Holiday Park,Ward 2,2,Spanish,English,French,Ukrainian,Cree,German, North Park,Ward 1,2,Tagalog,Ukrainian,French,German,English,, Confederation Park,Ward 3,3,English,French,Spanish,Urdu,Tagalog,, Meadowgreen,Ward 2,1,Arabic,English,Sino-Tibetan languages,Tagalog,Ukrainian,, U of S Lands South Management Area,Ward 1,0,Hindi,Chinese,Mandarin,Arabic,English,Bengali, Parkridge,Ward 3,2,Ukrainian,French,Tagalog,Semitic languages,Spanish,Arabic,English Arbor Creek,Ward 10,0,Semitic languages,Ukrainian,Chinese,Arabic,French,English, Stonebridge,Ward 7,2,English,Urdu,French,German,Chinese,, Central Industrial,Ward 1,0,Gujarati,Telugu,Punjabi,English,Urdu,, Richmond Heights,Ward 1,0,Ukrainian,French,Russian,German,English,, Buena Vista,Ward 6,1,Spanish,English,German,French,Ukrainian,, City Park,Ward 1,0,French,Tagalog,Ukrainian,English,German,, Avalon,Ward 7,2,German,French,Ukrainian,English,Chinese,, Lawson Heights Suburban Centre,Ward 5,1,German,Ukrainian,French,Dutch,English,, University Heights Suburban Centre,Ward 10,1,Ukrainian,German,French,English,Semitic languages,, Wildwood,Ward 9,2,German,English,French,Chinese,Ukrainian,, Varsity View,Ward 6,1,English,Tagalog,Spanish,French,German,Chinese, Massey Place,Ward 4,0,Urdu,English,Tagalog,Ukrainian,Spanish,, Montgomery Place,Ward 2,1,French,English,Spanish,German,Ukrainian,, Silverspring,Ward 10,2,French,Chinese,German,English,Ukrainian,, Eastview,Ward 7,2,English,French,German,Tagalog,Ukrainian,, Lawson Heights,Ward 5,5,German,Ukrainian,Tagalog,English,Gujarati,, Nutana,Ward 6,1,Ukrainian,German,French,English,Chinese,, Mayfair,Ward 1,1,English,Cree,Tagalog,German,French,, Willowgrove,Ward 10,2,Urdu,Ukrainian,English,Chinese,French,, Pacific Heights,Ward 3,1,English,Tagalog,Vietnamese,French,German,, Nutana Suburban Centre,Ward 9,2,French,Ukrainian,German,English,Urdu,, Westmount,Ward 2,1,French,Tagalog,Cree,English,Sino-Tibetan languages,, Central Business District,Ward 6,0,Tagalog,German,English,French,Ukrainian,, Fairhaven,Ward 3,2,Cree,English,French,Spanish,Tagalog,Ukrainian,German Lakeview,Ward 9,2,French,Chinese,Ukrainian,German,English,, Silverwood Heights,Ward 5,2,English,Tagalog,Ukrainian,German,French,, Airport Business Area,Ward 5,0,Cree,English,,,,, Kelsey - Woodlawn,Ward 1,0,French,German,Cree,English,Tagalog,, Lakeridge,Ward 9,2,Cantonese,Chinese,English,French,Ukrainian,, King George,Ward 2,1,French,English,Ukrainian,German,Cree,, Dundonald,Ward 4,2,Spanish,German,Vietnamese,Tagalog,English,, Riversdale,Ward 2,0,Cree,Cantonese,Mandarin,Chinese,English,, Caswell Hill,Ward 2,1,English,Cree,French,German,Tagalog,, Lakewood Suburban Centre,Ward 9,0,Chinese,Mandarin,Arabic,Urdu,English,, Sutherland,Ward 1,2,English,Ukrainian,Arabic,Urdu,German,French, Brevoort Park,Ward 8,2,Ukrainian,French,Chinese,Tagalog,English,, Exhibition,Ward 7,1,Spanish,English,Ukrainian,Bengali,French,German, College Park East,Ward 8,2,Urdu,French,German,English,Tagalog,, Westview,Ward 4,3,English,Tagalog,Cree,Ukrainian,German,, Nutana Park,Ward 7,1,French,Ukrainian,Chinese,German,English,, Holliston,Ward 6,1,Ukrainian,Tagalog,Chinese,English,German,, Haultain,Ward 6,1,French,Tagalog,German,Ukrainian,English,, College Park,Ward 8,1,Ukrainian,Chinese,English,Urdu,Tagalog,, Queen Elizabeth,Ward 7,2,German,French,Ukrainian,Spanish,English,, Hampton Village,Ward 4,2,Punjabi,Tagalog,Urdu,Spanish,English,, Rosewood,Ward 9,2,Hindi,Chinese,Korean,Urdu,English,Mandarin, Erindale,Ward 10,0,Chinese,Ukrainian,French,Arabic,English,, Confederation Suburban Centre,Ward 3,0,Cree,Tagalog,Urdu,French,English,Spanish, Pleasant Hill,Ward 2,1,Cree,Tagalog,Bengali,Ukrainian,English,, Adelaide/Churchill,Ward 7,2,Ukrainian,German,Tagalog,French,English,, Mount Royal,Ward 4,3,Spanish,English,Tagalog,Ukrainian,German,, Forest Grove,Ward 1,2,French,Arabic,Ukrainian,English,German,, Hudson Bay Park,Ward 1,1,Ukrainian,French,English,German,Tagalog,, River Heights,Ward 5,2,German,French,Ukrainian,English,Tagalog,, The Willows,Ward 7,0,English,Chinese,German,,,, Grosvenor Park,Ward 6,1,French,English,German,Ukrainian,Chinese,Mandarin,Arabic Greystone Heights,Ward 8,1,English,German,Chinese,French,Urdu,, Briarwood,Ward 8,0,Semitic languages,Chinese,Cantonese,Ukrainian,English,, 

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

Step: 3

blur-text-image

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

=+ (c) Write out (8.56) explicitly for the case s = 2.

Answered: 1 week ago