Question

In: Computer Science

Write a function which lets the user enter English words. The user can keep entering English...

Write a function which lets the user enter English words. The user can keep entering English words as long as the user has not entered the word “exit”. Once the user enters “exit” the function will return and print the list of all distinct words starts with English alphabets. Like: A: Ali, apple, … B: Bob, book … until Z. Write a python program for this question. Use main function.

Solutions

Expert Solution

RAW CODE

def wordswrap():
    word_list = []
    print("Enter Words")
    while(1): ### This is infinite loop, runs till breaked or returned
        word = input()
        if word.lower() == 'exit':
            final_dict = {}
            for i in set(word_list):
                a = i[0] ### First alphabet of word
                ### Here we are using lower to  collect all set of words having capital of small letter in a single alphabet
                ### Set finds the unique ones from them.
                data = set([word.capitalize() for word in word_list if (word.lower()).startswith(a.lower())]) ## Find all words starting with letter
                string = ", ".join(data) ### This will make a string from list
                final_dict[a.upper()] = string
                #final_list.append(string)
            return list(sorted(final_dict.items())) ### converting dictionary to list of tuples
        word_list.append(word) ## If word is not "exit", append in the list
        
if __name__ == '__main__': ### This is the main function
    list_of_unique_words = wordswrap() ### Calling function.
    for alphabet,words in list_of_unique_words:
        print(alphabet,": ",words) ### Printing Alphabets and their corresponding words in capitalize form.

SCREENSHOTS (CODE AND OUTPUT)

CODE

OUTPUT

##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####


Related Solutions

Write a C++ function that lets the user enter alphabet letters into a static char array...
Write a C++ function that lets the user enter alphabet letters into a static char array until either the user enters a non-alphabet letter or, it has reached the MAXSIZE. You can use the isalpha([Char]) function to check if the input is an alphabet letter or not. void fillArray (char ar[], size_t& size){ // this is the function prototype }
C++ Write a program that lets the user enter a two letters which are f and...
C++ Write a program that lets the user enter a two letters which are f and s with a length of 5. And outputs how many times it was occurred and lists the 2 most repeating pattern with 5lengths of f and s. The output display should always start at three-f(s) .Include an option where user can retry the program. Example: Input: sssfsfsfssssfffsfsssssfffsffffsfsfssffffsfsfsfssssfffffsffffffffffffssssssssfffsffffsssfsfsfsfssssfffsssfsfsffffffssssssffffsssfsfsfsss Output: The most repeating 5lengths of pattern is: fffsf and occurred 6times. Output2: The second most repeating...
How to write a C++ program that lets the user enter a string and checks if...
How to write a C++ program that lets the user enter a string and checks if it is an accepted polynomial. Accepted polynomials need to have one term per degree, no parentheses, spaces ignored.
Write a C++ program that lets the user enter the total rainfall for each of 12...
Write a C++ program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order): the total rainfall for the year,     the average monthly rainfall,     and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November,...
Write a Java program that lets the user keep track of their homemade salsa sales. Use...
Write a Java program that lets the user keep track of their homemade salsa sales. Use 5-element arrays to track the following. The salsa names mild, medium, sweet, hot, and zesty. The number of each type sold. The price of each type of salsa. Show gross amount of money made (before tax). Calculate how much the user owes in sales tax (6% of the amount made). Then display the net profit (after subtracting the tax).
- Write a function with no input parameter which keeps asking the user to enter positive...
- Write a function with no input parameter which keeps asking the user to enter positive numbers until the user enters an invalid input. (An invalid input is an input which includes at least one alphabet, like 123d4). The program should print the Max and Min of the numbers the user had entered as well as the distance between the Max and Min. (Remember to calculate the absolute distance). The function does not return anything
Write a program in C that lets the user enter a message using SMS Language(e.g. lol,...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol, omg, omw etc.), then translates it into English (e.g. laughing out loud, oh my god, on my way etc.). Also provide a mechanism to translate text written in English into SMS Language. needs to be able to translate at least 10 sms words
In Python: Design a program that lets the user enter the total rainfall for each of...
In Python: Design a program that lets the user enter the total rainfall for each of the 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts. However, to start, do not ask the user for input. Instead, hard code the monthly rainfalls as a list in your program, and then use the list to determine how to conduct the processing...
Create a JavaFX application that lets the user enter the food charge for a meal at...
Create a JavaFX application that lets the user enter the food charge for a meal at a restaurant. For example, if $20 is entered as a food charge for a meal then $3.6 should be displayed for the tip, $1.4 should be displayed for sales tax, and $25 should be displayed as a total of all three amounts. Modification 1: create a text box (not a pop up) for the user to enter a percent tip (don't just hardcode it...
Write a function posnum that prompts the user to enter a positive number and loops to...
Write a function posnum that prompts the user to enter a positive number and loops to error-check. It returns the square root of the positive number entered by the user. It calls a subfunction in the loop to print an error message. The subfunction has a persistent variable to count the number of times an error has occurred. Here is an example of calling the function: >> squarerootvalue = posnum Enter a positive number: -5 Error #1: Follow instructions! Does...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT