所以我想要这样的文字:
pretty = [beautiful, attractive, good-looking]
在 python 中,我有来自用户的输入。
UserInput= input()
我想检查 UserInput 是否与列表中的任何单词匹配。如果有匹配项,我想替换与“Pretty”匹配的单词。
我试过这个。
userInput = input()
userInput.split()
for word in userInput:
if word in pretty:
userInput.replace(word,"pretty")
这没有任何作用。它不会替换匹配的单词。
如果我有多个列表并想要检查所有列表,还有一个问题。最好的方法是什么?