Implement a function that takes a filename as input

Assignment Help Python Programming
Reference no: EM131670719

Task 1

Implement a complete version of an Array-Based List. Use 50 as the maximum number of elements. To create arrays use the method build_array from referential_array.py as discussed in the Lectures. Your List should include implementations for the following 10 functions:

- str (self): Returns a string representation of the list. Structure the string so that there is one item per line. Called by str(self)
- len (self): Returns the length of the list. Called by len(self)
- contains (self, item): Returns True if item is in the list, False otherwise. Called by item in self
- getitem (self, index): Returns the item at index in the list, if index is non-negative. If it is negative, it will return the last item if index is -1, the second-to last if index is -2, and so on up to minus the length of the list, which returns the first item. The function raises an IndexError if index is out of the range from -len(self) to len(self). Called by self[index]
- setitem (self, index, item): Sets the value at index in the list to be item. The index can be negative, behaving as described above. Raises an IndexError if index is out of the range from
-len(self) to len(self). Called by self[index] = item
- eq (self, other): Returns True if this list is equivalent to other. Called by self == other

- append(self, item): Adds item to the end of the list. Remember the underlying array is and should remain of fixed size. The operation should raise an Exception if the list is full.
- insert(self, index, item): Inserts item into self before position index. The index can be negative, behaving as described above. Raises an IndexError if index is out of the range from -len(self) to len(self).
- remove(self, item): Deletes the first instance of item from the list. Raises a ValueError if item does not exist in self
- delete(self, index): Deletes the item at index from the list, moving all items after it towards the start of the list. The index can be negative, behaving as described above. Raises an IndexError if index is out of the range from -len(self) to len(self).
- sort(self, reverse): Sorts the items in the list in ascending order if reverse is False or descending order if is reverse is True. Pick your favourite sorting algorithm from those covered in the Lectures.

Task 2

Modify your list implementation so that the size of the underlying array is dynamic. The base size of the array is 20 and should never be less than 20. However, if the list becomes full, it is resized to be 2 times larger than the current size. Likewise, the underlying size should decrease by half if the underlying array is larger than the base size but the content occupies less than 1 of the available space. When resizing the list, retain the contents of the list. That is, when it is initially filled, it will be resized to 20 items, then 40, while retaining the contents initially in it. The same happens when the size of the array shrinks.

Task 3

Implement a function that takes a filename as input and reads it into an instance of the class you implemented on Task 2. For each line in the file, store it as a single item in the list.

Background
The editor ed was one of the first editors written for UNIX. In this prac we will use the Array-Based list to implement a version of a line-oriented text editor based on ed. The text editor ed is very similar to the common UNIX text editors vi and vim (it is in fact their
predecessor).

Important: Our commands will be different from the ed commands.

To implement a simple line-oriented text editor, the idea is as follows. Suppose a file contains the following lines:

Yossarian decided not to utter another word.

where the string "Yossarian decided" is considered to be in line 1, "not to utter" is considered to be in line 2, etc. We want to store every line in the file in a data type that allows users to easily manipulate (delete/add/print) any line by simply providing the line number they want to modify. This means we should use a list data type (as opposed to a stack or a queue).

Task 4
Write a text editor as a Python program that allows a user to perform the 6 commands shown below using a menu. It is advisable that the Editor itself is a class with an attribute containing an list of lines. The list should be the type you have implemented on Task 2.

insert num: which inserts a line of text (given by the user) in the list before position num, and raises an exception if no num is given
read filename: which opens the file, filename, reads all the lines in from the file, put each line as a separate item into a list, and then closes the file.
write filename: which creates or opens a file, filename, writes every item in the list into the file, and then closes the file.
print num1 num2: which prints the lines between positions num1
and num2, if num1 < num2.
delete num: which deletes the line of text in the list at position num, and deletes all the lines if no num is given.
search word: which takes a word and prints the line numbers in which the target word appears. Search should be case insensitive.
Search should work as expected in a standard text editor, for example ignoring punctuation. This function must be accessible through the menu via commands search and count.
quit: which quits the program.

Important: All errors should be caught and a question mark, ?, should be printed when an error occurs. Negative number lines are possible and should be handled following the convention described for the original list implementation. For example, num = -1 refers to the last line of the text.

Tip: When you are testing your code, it is handy to have a source of reasonably large text files that you can use as test data. There is a huge repository of public domain text files at Project Gutenberg's websites. The Australian Project Gutenberg repository is at gutenberg website. You are encouraged to download a couple of ebooks from here and use them to make sure your code can deal with large files. Be sure to download plain-text format, though - your program is not expected to deal with other formats.

Task 5

Re-implement your editor using a Linked List instead of an Array-based list. The idea is to re-create the ADT now using the linked structure. If done properly, switching your text-editor to a Linked List implementation should take no more than changing a single line. To ensure this, make sure that the List ADT is implemented with the same functions and function signatures in both, Array-based and Linked versions. Write a page of text, using what you know of theory to analyse how the performance of your text editor would change when switching implementations.

Task 6

The sequence of actions made in a text editor can be stored during execution to facilitate undoing actions. When a user chooses to undo an operation the most recent action should have its changes reversed. This indicates that a last in, first out data structure would be suitable for storing the actions.

Implement a Stack ADT based Linked Nodes, and use it to implement in your editor the undo feature. Add this to your menu using the command undo.

Verified Expert

This assignment involves writing Python code. Totally 6 tasks are involved the first task involves writing code for the array based list and task 2 involves expanding or shrinking the array based on the number of elements stored in the list. The task 3 involves reading the item from the file. The task 4 involves writing python editor program. The task 5 involves converting the array based list to linked list. The task 6 involves adding extra undo functionality to task 5 editor program. For all task python code is written and output is attached in the documentation

Reference no: EM131670719

Questions Cloud

Public relations and strategic communication : What is the difference between Public Relations and Strategic Communication?
What is the scarcity rationale : What is the scarcity rationale? Does the Internet, with its plethora of music and video entertainment, render the scarcity rationale moot?
Social benefit of public relations practice : Ultimately, public relations is judged by its impact on society. Which one of the following is NOT considered a social benefit of public relations practice?
What do you currently understand about microbiology : What do you currently understand about microbiology? What personal experiences, if any, have you had regarding infection control in hospitals
Implement a function that takes a filename as input : FIT1008 - Implement a function that takes a filename as input and reads it into an instance of the class you implemented on Task 2. For each line in the file
Could food shortages bring down civilization : Could food shortages bring down civilization.Do you think these components or goals will be met in 50 years? Why or why not.
Provide a background of the firm industry and economy : Provide a background of the firm, industry, economy, and outlook for the future. Conclude with recommendations for the future analysis of the company.
What kind of truth does journalism pursue : What kind of truth does journalism pursue? The mere accuracy of facts cannot necessarily reveal truth, why?
Given the five functions of journalism : Given the five functions of journalism: Accountability, Conflict resolution, representation, deliberation, and information dissemination

Reviews

inf1670719

1/9/2018 2:25:46 AM

Great work. exceptionally intensive and the expert finished every one of my python assignments in the style, well structured. He did what was asked and was done before the due date provided. Thanks a lot

inf1670719

12/1/2017 4:24:11 AM

Please find at the attachment some example code that might help with the assignment. 2542125145852525887_1Julians Live Code-2071011 1.zip 254212134335887_2Julians Live Code-2071011.zip Please find the attachment 25435862_1referential array.py Please find the attachment 25435845_1referential array.rar

len1670719

10/6/2017 8:43:16 AM

Testing For this prac, you are required to write: (1)a function to test each function or method you implement, and (2) at least two test cases per function. There is no need to test menu functions, but all ADT operations should be tested separately. The cases need to show that your functions or methods can handle both valid and invalid inputs.

len1670719

10/6/2017 8:43:07 AM

Please write test functions and explanation Objectives of this practical session To be able to implement and use basic containers in Python. Note: • You should provide documentation and testing for each piece of functionality in your code. Your documentation needs to include pre and post conditions, and information on any parameters used. • Create a new file/module for each task or subtask. • Name your files task[num]_[part] to keep them organised.

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd