I want the user to input lyrics to the program (this will later be extended to searching a website, but i dont currently want help with that) and the program will tell me if the inputted info contains a word from a list.
banned_words = ["a","e","i","o","u"] #This will be filled with swear words
profanity = False
lyrics = input ("Paste in the lyrics: ")
for word in lyrics:
if word in banned_words:
print("This song says the word "+word)
profanity = True
if profanity == False:
print("This song is profanity free")
This code just outputs 'This song is profanity free.'
There are several ideas I'd recommend:
str.split.setfor O(1) lookup. This is denoted by{}instead of[]used for lists.returnas soon as a swear word is reached. You then no longer needelsestatements.str.casefold.Here's an example: