【问题标题】:Finding words from dictionary in input()在输入()中从字典中查找单词
【发布时间】:2018-08-02 15:57:57
【问题描述】:

我想做的事情背后的想法是:用户输入某种文本。如果他的文本包含一些单词(例如:“potato”、“tomato”、“broccoli”),那么这些单词就会被打印出来。非常感谢您的帮助。

【问题讨论】:

    标签: python python-3.x user-input


    【解决方案1】:

    你可以这样做:

    words = ["word1", "word2", ... , "word10"]
    
    userInput = input("Type some text")
    
    for word in words:
        if word in userInput:
            print(word)
    

    【讨论】:

    • 非常感谢
    • 欢迎您,如果这是一个可行的解决方案,请随时接受答案,但不必:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 2011-02-07
    • 2016-03-04
    • 2012-12-05
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    相关资源
    最近更新 更多