QuestionQuestion

Python Exercise
Part 1: A word, such as “hello”, is a list of letters. So, the concept of frequent property can be applied to words as well. For example, “keen”, “polo” and “sins” are frequently equal; “assassins” is frequently more than “aardvark”, which in turn is frequently more than “zebras”.
i) The file “words.txt” contains a very long list of English words. Write a function, readWords(), to load this file into a list. Before attempting this question, it is advisable to peek ahead at the next question to help choosing the most appropriate representation for the list of words.Verify that the solution works by writing the content of the list onto another file, for example, “frequent.txt”. Then compare the two files, for example, using the terminal command:diff words.txt frequent.txt
ii) Write a function, sortWords(words), to sort the list of words (see part (i)) according to “frequently more” relation. For example, “assassins” should appear before “aardvark”. Frequently equal words should appear in alphabetical order. For example, “daddy” should appear before “mummy”.Test the function to sample the first 20, the last 20 and some other 20 in the middle.
iii) Write a function, findEqual(words, word), to list all entries in words that are frequently equal to the given word.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

def loadWords():
    words = []
    f = open("words.txt")
    for line in f:
       line = line.strip()
       words.append(line)
    f.close()
    f = open("frequent.txt",'w')
    for word in words:
       f.write(word + '\n')
    f.close()
    return words

# Sort the list of words accordingly to frequency
def sortWords(words):
    d = {}
    for word in words...

By purchasing this solution you'll be able to access the following files:
Solution.PNG, Solution.py and Solution.txt.

50% discount

Hours
Minutes
Seconds
$30.00 $15.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats