Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON 3 LANGUAGE write a read_db function that coverts the db1.txt file in the format of that dictionary Write a read_db function takes an

IN PYTHON 3 LANGUAGE

write a read_db function that coverts the db1.txt file in the format of that dictionary Write a read_db function takes an open-file as an argument; it returns a dictionary (dict or defaultdict) in the form illustrated below). The input file will consist of some number of lines; each line specifies a product, followed by any number of warehouses and the inventory at each warehouse (always a non-negative integer; don't check it). All these different items are separated by colons (:) and contain no internal spaces.

the db1.txt file contains the lines brush:Irvine:3 comb:Irvine:2:Newport:1 wallet:Irvine:2:Tustin:3 stapler:Newport:0 keychain:Tustin:3 pencil:Tustin:4 For this file, read_db returns a dictionary whose contents are: {'Irvine': {'brush': 3, 'comb': 2, 'wallet': 2}, 'Newport': {'comb': 1, 'stapler': 0}, 'Tustin' : {'keychain': 3, 'pencil': 4, 'wallet': 3}}

This data structure means that 1. The Irvine warehouse stocks 3 brushes, 2 combs, and 2 wallets 2. The Newport warehouse stocks. 1 comb, and 0 staplers. 3. The Tustin warehouse stocks 3 keychains, 4 pencils, and 3 wallets.

So, each line from the file will put some information into the dictionaries. Note that each line in the file will have a unique product: you will never see the same product on multiple lines; also, each line will contain no duplicate warehouses: you will never see multiple appearances of a warehouse on the same line. Some warehouse may inventory the same products, some warehouses may inventory unique products: e.g., wallets are warehoused in both Irvine and Tustin; keychains are warehoused only in Tustin.

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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions