Question
CODE:
def censor_words(sentence, list_of_words):
"""
The function takes a sentence and a list of words as input.
The output is the sentence after censoring all the matching words in the sentence.
Censoring is done by replacing each character in the censored word with a * sign.
For example, the sentence "hello yes no", if we censor the word yes, will become
"hello *** no"
Note: do not censor the word if it is part of a larger word.
For example, if the sentence is "no hello no yes noooo no" and the censor word
is no, then the output should be "** hello ** yes noooo **".
"""
pass # write your solution here (do not change the rest of the program)
  

# The program asks the user to enter the list of words to censor and -1 to stop
censor_list = []
while True:
word = input("")
if word=="-1":
break
censor_list.append(word)

# Then, the program asks the user to enter the sentence to censor
sentence = input("")

# we call our function with user input and print the output
print(censor_words(sentence, censor_list))

17.5 Final - Question 2 (string manipulation) Write a function to censor words from a sentence. LAB 17.5.1: Final - Question
0 0
Add a comment Improve this question Transcribed image text
Answer #1

def censor_words(sentence,list_of_words):

#iterating through each word

  for x in list_of_words:

#generating * string with x

    mask= "*" * len(x)

#replacing it with censor word

    sentence=sentence.replace(x,mask)

  return sentence

censor_list=[]

while True:

  word=input("")

  if word=="-1":

    break

  censor_list.append(word)

sen=input("Enter sentence: ")

print(censor_words(sen,censor_list))

https://GeneralSolidBooleanlogic.koteswariinduri.repl.run m main.py saved 1 def censor_words (sentence, list_of_words): #iter

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
CODE: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """...

    PYTHON PLEASE Write a function to censor words from a sentence code: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as input. The output is the sentence after censoring all the matching words in the sentence. Censoring is done by replacing each character in the censored word with a * sign. For example, the sentence "hello yes no", if we censor the word yes, will become "hello *** no" Note: do not censor the...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • 5.19 LAB: Contains the character Write a program that reads an integer, a list of words,...

    5.19 LAB: Contains the character Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list will always contain less than 20 words. Each word will always contain less than 10 characters...

  • Define a function called collapse() which takes a list as input. Each element of the list...

    Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • Answer the 2 questions below related to this function. # words is a list of strings....

    Answer the 2 questions below related to this function. # words is a list of strings. # This function returns the list of all groups of anagrams. # Sample input: ["yo", "act", "flop", "tac", "cat", "oy", "olfp"] # Sample output: [["yo", "oy"], ["flop", "olfp"], ["act", "tac", "cat"]] def groupAnagrams(words):    anag = {}    for word in words:        table = [0] * 128        for ch in word:            table[ord(ch)] += 1        aKey...

  • this us python plz follow the instructions while u solving I need the code and sane...

    this us python plz follow the instructions while u solving I need the code and sane output QUESTION 1 Write a program that performs the following: 1) request a sentence (at least two words with no punctuation marks) input by the user 2) display the first word 3) display the last letter of the first word 4) display the last word 5) display the first letter of the last word input text can be any content just make sure to...

  • Write a spell checker that stores a set of words, W, in a hash table and...

    Write a spell checker that stores a set of words, W, in a hash table and implements a function, spellCheck(s), which performs a spell check on the string s with respect to the set of words, W. If s is in W, then the call to spellCheck(s) returns an iterable collection that contains only s, because it is assumed to be spelled correctly in this case. Otherwise, if s is not in W, then the call to spellCheck(s) returns a...

  • I need the following done in MASM (Assmebly or ASM) This program must use Irvine Library and the outline for the code is...

    I need the following done in MASM (Assmebly or ASM) This program must use Irvine Library and the outline for the code is below (Kip irvine) Write an assembly language program to input a string from the user. Your program should do these two things: 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   ...

  • Write a program in python that asks the user to input a sentence. The program will...

    Write a program in python that asks the user to input a sentence. The program will ask the user what two letters are to be counted. You must use a “for” loop to go through the sentence & count how many times the chosen letter appears in the sentence. You are not allowed to use python built-in function "count()" or you'll get a Zero! Output will show the sentence, the letter, and the number of times the letter appears in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT