Question

Please write a function three(string) that return a string that all three-letter words are replaced by...

Please write a function three(string) that return a string that all three-letter words are replaced by ***.  

For example:

three("submit only one question per post.  ") return: "submit only *** question *** post. "

Please using Python!

Homework Answers

Answer #1

Python code:

#defining three function
def three(string):
    #splitting it into words list
    string=string.split()
    #looping each word
    for i in range(len(string)):
        #checking if its length is 3
        if(len(string[i])==3):
            #replacing it with ***
            string[i]="***"
    #converting it back to string
    return " ".join(string)
#calling three function for a sample value and printing result
print(three("submit only one question per post."))


Screenshot:


Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a recursive function block_count(string) to return the number of blocks consisting of the same letter...
Write a recursive function block_count(string) to return the number of blocks consisting of the same letter in the given input string. Example. >>> block_count ('AABBCCBBDDD') 5 >>>block_count ('GGABAA') 4
using the python Write a function oneSpaceAfterPeriod( String Parameter ) that will return a string with...
using the python Write a function oneSpaceAfterPeriod( String Parameter ) that will return a string with one space after every period. Another function twoSpaceAfterPeriod (String Parameter) that will return a string with two spaces after every period. It is also a common error to forget to capitalize the first word after a period. Write a function to correct this and return the corrected paragraph.
4. Create a function, which takes as input a string and a letter. Determine whether or...
4. Create a function, which takes as input a string and a letter. Determine whether or not the letter is present in the string. The function should return a logical true/false if the given letter is present/absent. HINT: use find and isempty. Please anyone helping me with this question can you code using Matlab software, please.
write a function call character_thing (string, character) that takes in a string and a character. The...
write a function call character_thing (string, character) that takes in a string and a character. The function will return the number of times the character appears in the string. please be in python
1.Write a function which takes a string that contains two words separated by any amount of...
1.Write a function which takes a string that contains two words separated by any amount of whitespace, and returns a string in which the words are swapped around and the whitespace is preserved. Hint: use regular expressions where \s detects the whitespaces in a string. Example: given "Hello     World", return "World         Hello" 2.Pandas exercises: Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. Write a python program using Pandas to...
Write a python function called unique words that takes a phrase as an input string and...
Write a python function called unique words that takes a phrase as an input string and returns a list of the unique words found in that phrase. The words should be listed in alphabetical order.
Using python, please do the following. 1. Write regular expressions. (a) Capture any string that contains...
Using python, please do the following. 1. Write regular expressions. (a) Capture any string that contains at least three digits. (b) Capture any word that starts with one lowercase character, and either ends with two digits or with three vowels. 2. Given the following statements: string = """ Supreme executive power derives from a mandate from the masses , not from some farcical aquatic ceremony .""" words = string . split () Write a short program, using the re module,...
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
solve in python 3.8 please The question is about Strings Modify your function so that it...
solve in python 3.8 please The question is about Strings Modify your function so that it can handle the following two situations: The string given as an argument has no characters. In this case, you should return the empty string. The string given as an argument has one character. In this case, you should return the one-character string given to you. Without any consideration for these cases, your function probably causes an error or returns the wrong result in the...