python - 如何在mysql中匹配类似于like的python字符串
问题描述
a = "This is some text"
b = "This text"
我想比较 a 中的变量 b 并且即使文本包含两个以上的单词也应该返回 true
a = "This is another text here"
b = "This another here"
即使我在 a 中比较 b 应该在 python 中返回 true
条件:True
==b
找到所有单词,顺序相同,在a
.
在上面的例子中,单词必须是相同的顺序和大写/小写。
解决方案
a = "This is some text"
b = "This text"
c = 0
for i in b.split(): # check for each word in a
if i in a: c = c + 1 # if found increases the count
c>=2 # true
或者
len([value for value in a.split() if value in a.split()]) >= 2
推荐阅读
- sum - 如何使用 Apache Flink 在同一数据集上计算两个总和
- xml - 在 XSLT 中,如何使用存在多个相同节点的 ID 从节点中选择一个值?
- excel - 如何删除范围内的所有行?
- python - 打开函数在 python 上返回 404 错误
- r - googledrive unnest 返回未使用的参数错误
- ios - ViewController 不能使用通过 sender 参数传递的字符串
- linux - 从 Windows 到 Linux 的 C++ 可移植性
- javascript - node-config Config 在 typescript jest 上下文中是“未定义”吗?
- mysql - Django ORM 获取每个组的最新数据
- c# - 定位程序集的清单定义与程序集引用不匹配