CS-UY 1114代写、代做Python、Python语言程序调试调试Matlab程序|代做SPSS

Homework 9:DictionariesCS-UY 1114 NYU TandonSubmit your solution to all problems in a single Python file named YourNetID_hw9.py.Problem 1Consider the following dict, which provides a mapping of commonly misspelled words totheir correct spelling. Type the dictionary, exactly as given, into your file.respellings = {teh: the,relevent: relevant,lite: light,lol: haha,}Write a function respell, which takes a str argument and returns a string with thespelling corrected according to the content of the dict. Your solution must reference therespellings dictionary as its source of information. It can be used like this:>>> respell(I ate teh whole thing lol)I ate the whole thing hahaHint: use the split function to convert the input string into a list of words. Then useyou can use the join function to convert a (corrected) list of words back into a string.Hint: iterate over the list of words, replacing the current word if necessary and appendingit to an accumulator.Hint: use the in operator to determine if a particular word is a key in the dict. Userespellings[word] to get the value associated with word from the dict. If the wordisn’t in respellings, then the word is added to the output unchanged.Problem 2The position of a word in a string is the index of that word in list of words comprisingthe string. For example:ItwasφthebestofΚtimesΘitwastheworstνofφtimesφφWrite a function called “word_positions” with signature str -> dict (str, list (int)).It should return a dictionary whose keys are the words that occurCS-UY 1114作业代写、代做Python实验作业、Python语言程序作业调试 调试Matlab程序|代做SPSS in the argument string,and where the value associated to a given key is the list of positions at which that wordoccurs.For example:1>>> word_positions (It was the best of times it was the worst of times ){It: [0], was : [1, 7], the : [2, 8], best : [3], of: [4, 10],times : [5, 11], it: [6], worst : [9]}Hint: for the purposes of this problem you may assume that the string does not includeany punctuation. Also, you do not need to do any case normalization, so in this problemIt and it are considered different words. To obtain the list of words in a string, callthe split function:>>> welcome to the future .split()[welcome , to, the, future ]>>> nows the time.split ()[nows, the, time ]Problem 3Write a function called “commonest” that takes a dictionary like the one produced byword_positions as an argument and returns a key whose value list is the longest:>>> word_positions(He thought a thought hed never thought before){He:[0], thought :[1, 3, 6], a:[2], hed:[4], never :[5], before :[7]}>>> commonest(word_positions(He thought a thought hed never thought before))thought If the dictionary is empty, then your function should return the empty string. If there is a tie for the word with the longest list of positions, then your functionmay return any one of the most common words.Hint: iterate over the dictionary and compare the length of the list of positions for eachword to the length of the longest list seen thus far. Each time you find a new longest list,you will need to update both the commonest word its number of occurrences.转自:http://ass.3daixie.com/2018120413534732.html

你可能感兴趣的:(CS-UY 1114代写、代做Python、Python语言程序调试调试Matlab程序|代做SPSS)