Question

In: Computer Science

Python Language - Cant seem to get the correct output. Also, need through explanation if possible....

Python Language - Cant seem to get the correct output. Also, need through explanation if possible. much appreciative

XXXXX PYTHON>>>>>>>>>

Write a function named shareOneLetter that takes one parameter, wordList a list of words.

Create and return a dictionary in which each word in wordList is a key and the corresponding value is a list of all the words in wordList that share at least one letter with that word. There should be no duplicate
words in any value in the dictionary.

For example, the following is correct output:
print(shareOneLetter(horton))
{'I': ['I'], 'say': ['say', 'what', 'mean', 'and'], 'what': ['say', 'what', 'mean',
'and'], 'mean': ['say', 'what', 'mean', 'and'], 'and': ['say', 'what', 'mean', 'and']}

Solutions

Expert Solution

Source Code:

def ShareOneLetter(wordList):
   myDict={}
   for item in wordList: # for each word in wordList
       temp=[] # take an empty list to add items of word List which are matched
       for ch in item: # check for each charcter in item what are the matching words
           for ele in wordList: # this loop checks for all match words for the letter ch
               if (ch in ele) and (ele not in temp): # if the letter is matched in item and item not already present
                   temp.append(ele) # append to temp
       myDict[item]=temp # append the list of items matched
   return myDict # return the dictionary

horton=['I','say','what','mean','and']
print(ShareOneLetter(horton))

Sample input and output:


Related Solutions

Hello! *Need in C language also need full documentation/explanation of each line* Designing and implementing an...
Hello! *Need in C language also need full documentation/explanation of each line* Designing and implementing an Array of Structures - Course Grade Write a program that uses a structure to store the following data: Member Name Description Name Student name Idnum Student ID number Scores [NUM_TESTS] an array of test scores Average Average test score Grade Course grade Declare a global const directly above the struct declaration
const int NUM_TESTS = 4; //a global constant The program should ask the...
I cant not seem to get this right. I have tried and tried can I please...
I cant not seem to get this right. I have tried and tried can I please get help. Thank you! Writing a Modular Program in Java Summary In this lab, you add the input and output statements to a partially completed Java program. When completed, the user should be able to enter a year, a month, and a day to determine if the date is valid. Valid years are those that are greater than 0, valid months include the values...
*Need in C language also need full documentation/explanation of each line* Thank you! Write a program...
*Need in C language also need full documentation/explanation of each line* Thank you! Write a program that records high-score data from a simulated FIFA soccer game available online. The program will ask the user to enter the number of scores, create two dynamic arrays sized accordingly, ask the user to enter the indicated number of names and scores, and then print the names and scores sorted by score in descending order. The output from your program should look exactly like...
Add the result envidented by the python compiler. use python language. 1(a) A Give the output...
Add the result envidented by the python compiler. use python language. 1(a) A Give the output for the array([ 0, 1, 8, 27, 64, 125, 216, 343, 512, 729]) a. a[:6:2] = -1000 (ii) a[ : :-1] ) b. Display the values of 1D array using for loop?
 c. Write a code to print a 3D array?
 d. How to print the transpose of a 2D array?
 e Write a function to sort the array row and coloumn wise ?...
**** Using C Sharp **** ***If possible please include screenshot of output *** **Also, if possible,...
**** Using C Sharp **** ***If possible please include screenshot of output *** **Also, if possible, please provide info from .txt files created** You are to write a program which is going to use inheritance. It should start off with the base classes Account: contains the string name, int accountnumber, double balance. Savings: Derived from Account class, it should contain double interest rate. Checkings: Derived from Account class, it should contain double overdraftlimit. CreditCard: Derived from Checkings class, it should...
Make a calculator in python that always gives an explanation when the answer is output. It...
Make a calculator in python that always gives an explanation when the answer is output. It must be detailed
For my economy class I need to annswer these questions but I just dont get/cant find...
For my economy class I need to annswer these questions but I just dont get/cant find the right inf. The Presentville – Futureville case: 1. Explain what motivated each group to make the decisions they made.
What are the possible reasons for the development of the fractures in the lithosphere? Need explanation...
What are the possible reasons for the development of the fractures in the lithosphere? Need explanation and step by step solution and without plagrism
In python! please be thorough and read question carefully :) if possible, give explanation for code...
In python! please be thorough and read question carefully :) if possible, give explanation for code We’re going to create a class which stores information about product ratings on a website such as Amazon. The ratings are all numbers between 1 and 5 and represent a number of “stars” that the customer gives to the product. We will store this information as a list of integers which is maintained inside the class StarRatings. You will be asked to write the...
Explain why its possible to temporarily achieve output levels beyond the economys long-run potential. Why cant...
Explain why its possible to temporarily achieve output levels beyond the economys long-run potential. Why cant the high rates of output be sustained?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT