How To Match Words In A List With User Input In Python?
I am working on program which takes user input and replaces the words in a list with 'x'. eg is the word is sucks and user input is 'this word is sucks'. the output should be 'thi
Solution 1:
def main():
final_message = []
words = ['drat','crap','sucks']
counter = 0
userInput = input("Enter The Sentense: ") # use raw_input if you're using python2.X
truncatedInput = userInput[:140]
sentence = truncatedInput.split()
for word in sentence:
if word in words:
word = 'x' * len(word)
final_message.append(word)
print ' '.join(final_message)
Post a Comment for "How To Match Words In A List With User Input In Python?"