For Python
[25 pts] Write the method divisorList(aList, divisor) that takes in a list with elements of any data type and a divisor which is in the form of an integer. The output is a sorted list of only the integers that are divisible by the divisor.
Example: divisorList([1, 1, 12, 'a', 90, 34], 2) will return [12, 34, 90] since 12, 90, and 34 are all divisible by two. Note that the returned list is sorted from smallest to largest.
[25 pts] Write the method translate(translationDict, txt) that takes in a dictionary and a string. The dictionary contains keys of strings that have a value of another string. You will be translating the input string using the key-value pairs in the dictionary to a new string that has replaced all the words in the input string with the words' value in the dictionary. Your function should convert txt to all lowercase letters before making the translations. If a word in the string is not in the translation dictionary, the word will retain its original form.
Example: >>> myDict = {'up': 'down', 'down': 'up', 'left': 'right', 'right': 'left'} >>> text = 'up down left right forward' >>> translate(myDict, text) 'down up right left forward'
Thanks for the question.
Here is the completed code for this problem. Let me know if you have any doubts or if you need anything to change.
Thank You !!
================================================================================================
def divisorList(aList, divisor):
divisible_sorted_list = []
for number in aList:
try:
if number % divisor == 0:
divisible_sorted_list.append(number)
except:
continue
divisible_sorted_list.sort()
return divisible_sorted_list
def translate(translationDict, txt):
translated_string = ''
for key in txt.split():
key=key.strip().lower()
if translationDict.get(key) is None:
translated_string += key + ' '
else:
translated_string += translationDict.get(key).lower() + ' '
return translated_string[:-1]
myDict = {'up': 'down', 'down': 'up', 'left': 'right', 'right': 'left'}
text = 'up down left right forward'
translated=translate(myDict, text)
print(translated)
======================================================================================

For Python [25 pts] Write the method divisorList(aList, divisor) that takes in a list with elements...
GOALI Using your text editor, write the function sumSquares(aList). The function takes a list as ninput and returns (not prints) the sum of the squares of the all the numbers which absolute value s divisible by 3. If an element in the list is not a number, the function should ignore the value and ontinue. When the function receives an input that is not a list, code should return an error message o the user. Hints: review the type) or...
Define the functions in Python 3.8
1. Write a function most frequent n that takes a list of strings and an integer n, and that returns a dictionary where the keys are the top n most frequent unique words in the list, and the values are the frequency of each word: For example, most frequent n(text, 3) should return the dictionary {'is': 2, "the’: 3, 'of': 2}, and most frequent n(text, 2) could return either {'is': 2, 'the’: 3} or...
A Les Mills BODYPUMP instructor has a list of the weight plates for her classes and saved in a file. Each weight plate was stored with the weight (kg), color, and quantity. Write a program that reads in the data (a list of weight plates) from a file, and sort the plates by weight, and write the ordered list to the output file. Assume the input file plates.txt has the format of weight (double), color (one word string), followed by...
Summary
You will write an application to build a tree structure called
Trie for a dictionary of English words, and use the Trie to
generate completion lists for string searches.
Trie Structure
A Trie is a general tree, in that each node can have
any number of children. It is used to store a dictionary
(list) of words that can be searched on,
in a manner that allows for efficient generation of completion
lists.
The word list is originally stored...
QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...
Overview: file you have to complete is
WordTree.h, WordTree.cpp, main.cpp
Write a program in C++ that reads an input text
file and counts the occurrence of individual words in the file. You
will see a binary tree to keep track of words and their counts.
Project description:
The program should open and read an input file (named
input.txt) in turn, and build a binary search tree
of the words and their counts. The words will be stored in
alphabetical order...
For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...
Recursion and Trees Application – Building a Word Index Make sure you have read and understood · lesson modules week 10 and 11 · chapters 9 and 10 of our text · module - Lab Homework Requirements before submitting this assignment. Hand in only one program, please. Background: In many applications, the composition of a collection of data items changes over time. Not only are new data items added and existing ones removed, but data items may be duplicated. A list data structure...
60 points, Complete javadocs documentation required Be sure to submit all files (.java and dictionary.txt) required to run your program Background Boggle is a word game using a plastic grid of lettered dice, in which players attempt to find words in sequences of adjacent letters. The dice are randomly arranged in the grid, and players have 90 seconds to form as many words as possible from adjacent top-facing letters For example, the word SUPER is spelled in the gameboard to...
python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2.Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of...