如何从字符串中检测多个单词? (蟒蛇)

时间:2016-04-11 13:55:35

标签: python detect words

我需要创建一个程序,用户可以使用手机输入他们遇到的问题。由于回复可能是多个单词和行,我需要能够选择关键短语和单词,例如"没有打开"或者"破解"从答复。到目前为止,我所尝试的一切都没有奏效;不是真正的编程专家,最近才开始。

psuedo代码:

x=input("What is wrong with your phone?")
if "dropped" in x:
    print( #text )

我正在使用Python v3。

提前谢谢你。

3 个答案:

答案 0 :(得分:3)

这是一种方法:

x = input("What is wrong with your phone?")
keywords = ["doesn't turn on", "cracked", "dropped"]
if any(keyword in x for keyword in keywords):
    print("test")

答案 1 :(得分:2)

您可以使用int noteAqua = Color.parseColor("#1abc9c") colorPicker.setColors(new int[] {noteAqua}); ,然后使用split()

例如:

in

答案 2 :(得分:1)

您输入的代码没有任何问题。

override def run():List[Option[Student]] =
StudentDataCache.get(surname) match {
  case Some(i) => i.otherSiblings.map(siblings =>
    StudentDataCache.get(siblings) match {
      case Some(i) => Some(i)
      case None=> getStudentFromDatabase(siblings)
    }
  )
  case None =>
    getStudentFromDatabase(surname).get.otherSiblings.map(siblings => StudentDataCache.get(siblings) match {
        case Some(i) => Some(i)
        case None=> getStudentFromDatabase(siblings)
      }
    )
}
相关问题