Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A MapList is a mapping container, just like dictionaries. It is mutable and iterable and all items are unique. Also, similar to dictionaries, MapList contains

A MapList is a mapping container, just like dictionaries. It is mutable and iterable and all items are unique. Also, similar to dictionaries, MapList contains a group of keys and values. However, unlike dictionaries which are unordered, MapList is ordered. Therefore, a specific key always maps to a specific value, and both the key and value share the same index in the container.

Implement the class MapList which contains the following methods:

1- __init__: This is the constructor which initializes MapList. It receives two parameters: a list of keys and a list of values. The constructor should work if no parameters are passed, by creating an empty MapList.

2- is_empty: Returns True if the MapList is empty and False otherwise.

3- insert: Adds a pair of items to the MapList. The pair could be a list or a tuple. The first item is the key, and the second is the value. The pair should be added to the end of the container. For example, if the container already contains 4 items, then the new pair should be added at index 4 (remember first index is 0). The method should print an error message if the given parameter is invalid. You should be able to figure out the error scenarios by looking at the testing and output files.

4- remove(key): Receives a key and remove it, along with it mapped value from the container. A copy of the removed item should be returned in the form of a tuple: (key,value). If the given key is not found in the container, an error message is printed and None is returned.

5- index(key): Receives a key and find its index in the MapList container. If the key is not found, an error message is printed and -1 is returned.

6- get(key): Returns the value mapped by the given key. If the key is not found, it prints an error message and returns None.

7- The six comparison operators: Override the six comparison operators (==, !=, <, >, <=, >=). Comparison is done by only comparing the number of items in both MapLists.

8- to_list(): Returns a list version of the MapList. The output is a 2D list formatted as: [ [key1,value1], [key2,value2], ... ]

9- to_dict(): Returns a dictionary version of the MapList. The output is a dictionary containing unordered version of MapList, while maintaining the mapping.

10- clear(): Removes all items from the MapList object. Does not make any returns.

11- There are three more methods that you need to implement. Their names are not given to you. Figure them out by observing the testing and output file.

It is up to you how you want to implement the MapList class. You can use lists, dictionaries, tuples, stacks, queues, or any other container that we studied in this course. This is an ADT, and it should produce the expected output.

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

7 Describe the major retailer marketing decisions.

Answered: 1 week ago