Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7 Required Function: build map() buildmap() must take a single parameter, which is the location of a file. 1 You must open the file and

7 Required Function: build map()

buildmap() must take a single parameter, which is the location of a file. 1 You must open the file and build a substitution map from it; return the map.

The file format will be as described earlier in this file; as with the previous assignment, you must ignore any blank lines, or lines that contain comments.

You may assume that the file exists; you do not have to do any error checking to handle a situation where the file cant be opened.

7.1 asserts Your function must use asserts to make sure that each of the following is true,

for every line (except blank lines and comments): The line has exactly two words (we dont care about how much whitespace,

or where) Both words on the line must be a single character The same from character in the map must not be used twice.

Note that there are many other things that might be interesting to check, such as confirming that the to characters are not duplicated. Dont do these checks in this function; tolerate silly maps.

1Since this is a function - not the main program itself - do not do the chdir code. Assume that main() gives you a filename which will work, without changing directories.

6

8 Required Function: is valid map()

is valid map() does some more extensive error checking - more than is done bybuild map(). It is designed either to be used as a second step (sanity-checking something that build map() returned), or as checking a map that was build by hand, using some other process.

This function takes a single parameter (the map), and returns either True orFalse; it only returns True if all of the requirements are met. This function should never assert about anything; instead, return False if you find a problem.

9

This function must confirm that:

Every from character (the keys) and every to character (the values) are strings.

Also, every such string is exactly one character long. Also, none of those strings are the space, tab, or newline character.

HINT: What does this code do?

 if c in " \t ": 

There are no duplicate to characters.

The set of from characters is exactly the same as the set of to char- acters.

in python please!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions