Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python 2. (8 points) Here's a fun application of multisets: LEGO! Multisets can be used to represent collections of LEGO parts. Each type of

In Python image text in transcribed
2. (8 points) Here's a fun application of multisets: LEGO! Multisets can be used to represent collections of LEGO parts. Each type of part is assigned a unique ID, which serves as the keys in the dictionary. The values in the dictionary are how many of that part exist in the collection. I've provided several text files describing collections of LEGO parts. Each line of each file consists of a part ID, followed by one space and then how many of that part exists in the collection. The part IDs are based on actual IDs and color codes used on Write a function read_parts_list (filename) that reads a file formatted like the ones above, returning a multiset in dictionary representation. Note that a part ID may appear more than once in a single file. If this occurs, the dictionary should combine the values together into a single key. For example, suppose you have a file named sample.txt that contains these lines: 6541-1143070b11122484-8523070b-1156541-1113070b-114 Then calling read_parts_list ('sample.txt') should return a dictionary that looks something like this: {654111:5,3070b-11:10,2248485:2} 1 The function must return a bool value, either True or False. Page 2 of 4 COMP 2700 - Spring 2023 Lab 1 Due Fri., Feb. 24, by 2359 Central Python note: Here's an easy way to read a file in Python: with open( 'filename.txt') as f : content =fread(),splitlines() \# content is a list of strings. Each element of content contains one line of \# the file, *without* the ending line break

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions