相关疑难解决方法(0)

是否有列表的短包含功能?

我看到人们正在使用any收集另一个列表来查看列表中是否存在某个项目,但是有一个快速的方法可以做到吗?:

if list.contains(myItem):
    # do something
Run Code Online (Sandbox Code Playgroud)

python collections search contains list

473
推荐指数
4
解决办法
58万
查看次数

如何使用python在文本中查找关键字

作为项目的一部分,我必须能够识别用户输入的关键字.

例如,如果我输入"如何找到伦敦",它会看到伦敦这个词并找到.

我如何使用数组来使代码看起来更干净.

city = [London, Manchester, Birmingham]
where = input("Where are you trying to find")
  if(city in where):
    print("drive 5 miles")
  else:
    print("I'm not to sure")
Run Code Online (Sandbox Code Playgroud)

所以我只想知道如何在用户输入中找到数组中的单词.

这不是项目,而是类似的方式.

python text

2
推荐指数
1
解决办法
3477
查看次数

标签 统计

python ×2

collections ×1

contains ×1

list ×1

search ×1

text ×1