Guidelines

Use test-driven development and incremental development by solving ONE problem at a time.

2. In bash, START by going into the homework folder and creating the transform subfolder.

a. In the transform folder create two files with the touch command

  • transform.py module
  • simple.txt file

b. Launch Atom and 0pen the comp424 folder. In Atom's Project pane you should have the folder comp424 because you'll need access to the review folder in projects.

c. In Atom

  • Open simple.txt file and copy in it the content of this file:
python is a cool language
lots of libraries out there
more practice is helpful
best advice do not get discouraged
collaborate more
  • Open transform.py in comp424/homework/transform folder for editing.
  • In transform.py, write a module docstring with information about the module:
    • File name: transform.py
    • Purpose: Transform data
    • Author: enter your name
    • Created: The Date

d. Continue by following the guidelines below.

2. BEFORE you start your design:

a. Write a class header for the class Transform.

b. Write a class docstring that simply says: Has methods that transform data structures.

c. Inside the class, write

  • Two method stubs (header, docstring, and empty body) that solve the problems given in the Computational Problems section. The docstring uses the descriptions in the Computational Problems section and has three parts:
    • WHAT the method does
    • WHAT parameters the method has and their data types (excluding self)
    • WHAT the method returns: data type of return value
  • The full definition of the word_histogram() method:
    • Copy the function definition from oopreview.py and
    • Change the header by adding the self parameter.

3. Write THREE TEST CASES at the end of the Python module in a function named main()

a. Write the function docstring for main(). It simply says: Tests the Transform methods.

b. Create a Transform object and assign it to variable transform_obj.

c. Define a local variable called test_input to store the input value that is passed to the method calls.

d. Write method calls with test_input as argument and assign the return value to the result variable.

e. When ONE test case is completed:

  • Test the current state of your module with $ python transform.py
  • Debug if necessary until you have no Python errors.
  • Continue with the next test case

f. Test cases are chosen as follows:

The input variable for each test case of the longest_words(histogram) is defined as follows:

  • The FIRST test case test_input variable stores a dictionary object.
  • The SECOND test case input variable stores the return value from calling word_histogram('simple.txt').
  • The THIRD test case test_input variable stores the return value from calling word_histogram('scarlet.txt'). Copy the file scarlet.txt from your project 6 folder into the transform folder.

The input variable for each test case of the most_popular_words(self, file_name) is defined as follows:

  • The FIRST test case test_input variable stores 'simple.txt'.
  • The SECOND test case test_input variable stores the name of a new text file you create in the transform folder, , named second.txt.
  • The THIRD test case test_input variable stores 'scarlet.txt'.

4. Write your DESIGN in a separate file named README.md

a. Use Markdown simple tags to create heading with the names of the methods (use ###)

b. Include the header and docstring of the method and encompass it within the backticks ``` and ```

c. Describe the logical steps that the method will carry out.

d. Itemize the logical steps using the Markdown tag *

e. As you describe the logical steps:

  • Ask yourself WHY you have that step in order to justify your design decision
  • Ask yourself WHAT new variables you need to handle the data
  • Ask yourself HOW the logical steps fit together and whether they follow a PATTERN that helps you structure your design
  • Ask yourself HOW each logical step works.

f. Choose descriptive names for the new variables and use them in your explanations

g. Test the current state of your module with $ python transform.py

5. Write the IMPLEMENTATION of your method definitions

a. Follow the logical steps in the DESIGN

b. Use the f-string to form the string that prints out the result.

c. Test the current state of your module

d. Debug if necessary until you have no Python errors.

6. Apply Python coding style conventions and verify them with pycodestyle and pylint tools.

7. When you are satisfied with the DESIGN, IMPLEMENTATION, TESTING, and CODING STYLE of the FIRST problem

a. Move on to tackle the SECOND problem

b. Repeat the steps 3 to 6.

Computational Problems

Problem 1

Define a method longest_words(self, histogram) that finds and returns a list of the longest unique words corresponding to the keys in the dictionary histogram

histogram: dictionary
keys: strings
values: non-negative integers
Returns: list of strings of the same size
Testing requirements: To test the implementation of this method you must use three test cases

Problem 2

Define a method most_popular_words(self, file_name) that finds and returns a list of unique words that have the highest frequency in a text file.

file_name: name of a text file in current directory
Returns: list of strings
Testing requirement: To test the implementation of this method you must use three test cases
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.