例如,如果我有一个列表
list = ['brown', 'lazy', 'dog']
和两个句子:
1) "The quick brown fox jumps over the lazy dog."
2) "The quick brown fox jumps over the dog."
有没有办法确定所有字符串都出现在句子1中,而不是出现在句子2中?
答案 0 :(得分:0)
一些想法:
输入来自命令行作为参数,如果不是数组中的所有单词都存在,脚本将以代码1退出并显示“未找到”消息。
std::vector<std::vector<int>> v
{
{ 0,0,0 },
{ 0,0,0 },
{ 0,0,0 }
};
相同的概念,如果#!/bin/bash
sentence=$1
declare -a arr=("brown" "lazy" "dog")
for i in "${arr[@]}"; do
if [[ $sentence != *"$i"* ]]; then
echo "Not found"
exit 1
fi
done
字符串中未包含所有数组内容,则打印“未找到”。
$sentence
$words = array("brown", "lazy", "dog");
$sentence = "The quick brown fox jumps over the lazy dog.";
foreach($words as $word){
if(strpos($sentence, $word) === false){
echo "Not found";
}
}
words = ["brown", "lazy", "dog"]
sentence = "The quick brown fox jumps over the lazy dog."
for word in words:
if word not in sentence:
print "Not found"