检查另一个字符串中的单词列表 [英] Check list of words in another string

查看:38
本文介绍了检查另一个字符串中的单词列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在python中做这样的事情:

I can do such thing in python:

l = ['one', 'two', 'three']
if 'some word' in l:
   ...

这将检查列表中是否存在某些单词".但是我可以做相反的事情吗?

This will check if 'some word' exists in the list. But can I do reverse thing?

l = ['one', 'two', 'three']
if l in 'some one long two phrase three':
    ...

我必须检查字符串中是否有来自数组的单词.我可以使用循环来执行此操作,但是这种方式有更多的代码行.

I have to check whether some words from array are in the string. I can do this using cycle but this way has more lines of code.

推荐答案

if any(word in 'some one long two phrase three' for word in list_):

这篇关于检查另一个字符串中的单词列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆