Write a function mode that takes a single argument numlist

Assignment Help Computer Engineering
Reference no: EM131927670

Problem - e-stimation

(1 + 1/x)z < n < (1 + 1/x)x+1

for all positive number x.

One way to estimate e is via the following equation:

e ≈ i=0n 1/i!

where: i! = i x (i-1) x . . . x 1

and 0! Is defined to be 1.

That is, we calculate 1/i! for the values i = 0 up to (and including) i = n, and sum them all up.

Write function e_estimator (n) that takes a non-negative integer n as input and returns a float estimate of e based on the equation above.

Problem - For a While

Let's put this into action, in rewriting awhile loop to a for loop, in the context of the provided function allnum(strlist), which takes a list of strings strlist, and returns the list of strings which are made up exclusively of digits (in the same order the strings occurred in the original).

Note that rewritten function should behave identically to the original, and the only changes you should make are to the while loop and associated variables, to rewrite it as a for loop. Note also that in the rewritten version of the code, you should iterate over the elements of strlist directly, without indexing. Submissions which don't conform with both of these will be rejected, so be sure to follow the requirements of the problem carefully!

Problem - Least Vowel Words

Write a function least_vowel_words (text) that takes one argument text containing a block of text in the form of a str, and returns a list of unique word(s) with the lowest "vowel proportion" as a list. The vowel proportion is defined as the proportion of letters in the word which are vowels (e.g. the vowel proportion of life is 2/4 = 0.5). The returned list will have multiple elements if and only if there is a tie for lowest vowel proportion, and in this case, the elements should be ordered as they (first) appear in text.

"Words" should be assumed to be separated by whitespace (spaces, tabs or newlines). In all cases, all "words" should be converted to lower case and any punctuation should be stripped from the (right) end of the word, in the form of the following punctuation marks ONLY: commas (" , "), fullstops (" . "), colons (" : "), semi-colons (" ; "), exclamation marks (" ! "), question marks ("?"), single quotes (" ' "), double quotes ( ' " ' ), and hyphens (" - ").

Problem - Mode List

Write a function mode(numlist) that takes a single argument numlist (a non-empty list of numbers), and returns the sorted list of numbers which appear with the highest frequency in numlist (i.e. the mode).

Problem - Spiral Word

350_figure.png

In this case, the spiralled sequence of letters is in strictly descending order, as each letter comes before its (spirally) preceding letter in the alphabet. An example of an ascending spiral word (where every letter comes after its (spirally) preceding letter) is flush' ('f', 'h', 'l', 's', 'u'). An example of a non-spiral word, on the other hand, is 'all', as the spiral sequence of letters is not strictly ascending ('l' follows 'l').

Write the function spiral_word (word) that takes a single string argument word and returns a 2-tuple made up of bool values as follows:

  • the first bool indicates whether the word is a spiral word or not
  • the second bool indicates whether a spiral word is ascending or not (indicating either that it is descending, or that it's not a spiral word).

Problem - Symmetric Words

Write a function symmetric_words (wlist) that takes a single argument wlist containing a list of words each in the form of an all-lowercase non-empty str, and returns a sorted list of "symmetric" words. A symmetric word is defined as a word where for all values i, the letter i positions from the start of the word and the letter i positions from the end of the word are equidistant from the respective ends of the alphabet.

Problem - Top-5 Frequent Words

Write a function top5_words (text) that takes a single argument text (a non-empty string), tokenises text into words based on whitespace (once again, without any stripping of punctuation or case normalisation), and returns the top-5 words as a list of strings, in descending order of frequency. If there is a tie in frequency at any point, the words with the same frequency should be sub-sorted alphabetically. If there are less than five distinct words in text, the function should return the words in descending order of frequency (with the same tie-breaking mechanism).

Problem -While a For

OK, time now to rewrite a for loop as a while loop.

Mr Frodo is having second thoughts about the trip to Mordor. Being both a superstitious little chap and a Dungeons and Dragons fan, he carries a 20-sided dice wherever he goes. He decides that he will roll the dice a fixed number of times, and if his favourite number comes up, he will go to Mordor, and if not, he will return to the Shire. We will simulate the 20-sided dice through the use of the randint function from the random library (a topic that we will cover properly in Worksheet 13; for now, just accept that from random import randint gives you access to the function, which returns a random integer between the values of the first and second arguments, inclusive).

Given the provided function luck_tester, (lucky_number, max_rolls, di ce_si ze), which takes as arguments: (1) a lucky number lucky_number (3 in Mr Frodo's case: the number of trolls his uncle encountered in the Trollshaws); (2) the maximum number of dice rolls max_rolls; and (3) the dice size dice_si ze (in terms of the number of sides the dice has; 20 in Mr Frodo's case); all can be assumed to be integers. The function should return a string, of value depending on whether the lucky number comes up in the provided number of rolls of the dice or not; the precise strings are provided in the original code.

Note that rewritten function should behave identically to the original, and the only changes you should make are to the for loop and associated variables, to rewrite it as a while loop. Submissions which don't do this will be rejected, so be sure to follow the requirements of the problem carefully!

Problem - Authorship Attribution (Part 1)

The final part of Project 1 takes the form of an "authorship attribution" system, that is a system which attempts to determine who wrote a given document, based on analysis of the language used and style of that document. We will break the system down into multiple parts, to make it clearer what the different moving parts are, and make it easier for you to test your system.

The first step in our authorship attribution system will be to take a document, separate it out into its component words, and construct/return a dictionary of word frequencies. As we are focused on the English language, we will assume that "words" are separated by whitespace, in the form of spaces ('  '), tabs ('\ t ') and newline characters ( ' \ n ').

We will also do something slightly unconventional in considering each "standalone" non-alphabetic character (i.e. any character other than whitespace, or upper- or lower-case alphabetic characters) to be a single word.

Write a function authattr_worddict (doc) that takes a single string argument doc and returns a dictionary (dict) of words contained in doc (as defined above), with the frequency of each word as an int. Note that, as the output is a dict, the order of those words may not correspond exactly to that indicated below, and that the testing will accept any word ordering within the dictionary.

Problem - Authorship Attribution (Part 2)

The next step in our authorship attribution system will be to take two dictionaries of word counts and count the similarity between them. We will do this by:

1. ranking the two sets of words in descending order of frequency, and:

2. for corresponding word pairs, calculate the absolute difference in rank between the two.

If a word is found in one ranking but not the other, we will set the ranking for the second to the value max rank (provided as part of the function call). In the case of a tie in the word frequency ranking (due to multiple words having the same frequency), we will assign all items the same value, calculated as follows:

tied ranking + (number of tied items - 1)/2

Write a function authattr_oop(dictfreq1, dictfreq2, maxrank) that takes three arguments:

  • dictfreq1: a dictionary of words, with the (positive integer) frequency of each
  • dictfreq2: a second dictionary of words, with the (positive integer) frequency of each
  • maxrank: the positive int value to set the ranking to in the case that the word isn't in the dictionary of words in question

and returns a float out-of-place distance between the two (where the smaller the number, the more similar the two rankings are).

Problem - Authorship Attribution (Part 3)

The final step in our authorship attribution system will be to perform authorship attribution based on a selection of sample documents from a range of authors, and a document of unknown origin.

You will be given a selection of sample documents from a range of authors (from which we will learn our word frequency dictionaries), and a document of unknown origin. Given these, you need to return a list of authors in ascending order of out-of-place distance between the document of unknown origin and the combined set of documents from each of the authors. You should do this according to the following steps:

1. Compute a single dictionary of word frequencies for each author based on the combined set of documents from that author (provided in the form of a list of strings)

2. Compute a dictionary of word frequencies for the document of unknown origin

3. Compare the document of unknown origin with the combined works of each author, based on the out¬of-place distance metric

4. Calculate and return a ranking of authors, from most similar (smallest distance) to least similar (greatest distance), resolving any ties in the ranking based on an alphabetic sort

You have been provided with reference implementations of the functions authattr_worddict and authattr_oop from the preceding questions in order to complete this question, and should make use of these in your solution. These are provided via the from hidden_lib import authattr_worddict, authattr_oop statement, which must not removed from the header of your code for these functions to work.

Write a function authattr_authorpred (authordict, unknown, maxrank) that takes three arguments:

  • authordict: a dictionary of authors (each of which is a str), associated with a non-empty list of documents (each of which is a str)
  • unknown: a str contained the document of unknown origin
  • maxrank: the positive int value to set max rank to in the call to authattr_oop

and returns a list of (author, oop) tuples, where author is the name of an author from authordict, and oop is the out-of-place distance between unknown and the combined works of author, in the form of a float.

Attachment:- Assignment Files.rar

Verified Expert

This is a program written in python. This program is about the usage of list, dictionary and tuple in built functions in python. In this first part, the program uses dictionary to build unique words from the sentences and then finds the frequencies of the occurrences. In the second part we obtained the out-of-distance of an author and finally in the third part we compare the various sets of script from various authors to from a hierarchy of the out-of-distance to the author.

Reference no: EM131927670

Questions Cloud

Identify a new products and services opportunities : Identify a new product(s) and/or service(s) opportunities according to the Beacon Council South Florida Target Industries-Products.
How is a correctional facility operated under the model : During what time period was the model developed? Explain. Was it effective during that time period?
Was the parking lot clean and free of trash and debris : Was the parking lot clean and free of trash and debris? (Check for general cleanliness. Do not mark for small amounts of litter/paper/debris.)
Do you consider yourself more of a public-order advocate : What are the positive aspects of your chosen position for purposes of counterterrorism?
Write a function mode that takes a single argument numlist : Write a function mode(numlist) that takes a single argument numlist (a non-empty list of numbers), and returns the sorted list of numbers which appear
What are other names of entry level positions : What are other names of entry level positions? Is there more than one path one could take? What are the middle to upper level positions?
What was the percentage discount : The original price of a computer was $1128, but Fred bought it on sale for $823.44. What was the percentage discount?
What are the characteristics and histories of victims : Where and under what circumstances is prisoner suicide likely to occur? Be detailed in your response, and provide examples to support your arguments.
Prepare a professional report for qantas : PACC6006 Taxation Law - In the form of a professional correspondence you are required to prepare a professional report for Qantas

Reviews

len1927670

4/4/2018 3:59:52 AM

Student's comment - I have attached the relevant information for different tasks that I need help in to complete. e – estimation, For a While, Least Vowel Words, Mode list, Spiral word, Symmetric words, Top - 5 Frequent Words, While a For, Authorship Attribution (Part 1), Authorship Attribution (Part 2) and Authorship Attribution (Part 3). Could the code written up be basic/simple as possible? (Not using like lambda and other fancy codes).

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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