我已經修改了你的代碼的一些註釋了一下,檢查出來:
swearWords = ["mittens", "boob"]
phrase = raw_input('> ')
# Here I've split the phrase into words so we can iterate through
phrase_words = phrase.split(' ')
# Now we iterate through both the words and the swear words and see if they match
for word in phrase_words:
for swear in swearWords:
if word.upper() == swear.upper():
print "Found swear word:", swear
這裏就是我得到的,當我運行它:
C:\Users\John\Desktop>temp.py
> These are some swear words. Like boob or mittens maybe. Are those really swear
words?
Found swear word: boob
Found swear word: mittens
希望這有助於!
非常感謝!這很好。 – user2607110
@ user2607110:歡迎來到SO!如果這個答案有幫助,你應該[接受](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235)。 – dparpyani