擅长:python、mysql、java
<p>我猜您正在尝试查看字符串“是否是”列表中存在的任何字符串的一部分的颜色,以及是否要删除该列表元素。唯一的方法是在列表中循环(<strong>表示列表中的项),然后使用<strong>in</strong>关键字检查列表元素中正在搜索的子字符串。一个简单的方法是创建一个新列表,如果满足条件(即列表元素不包含您正在搜索的子字符串),则将列表元素复制到新列表中。但是,如果满足条件,您可以输入<strong>继续<strong>跳过它。你知道吗</p>
<p>编辑:如果您想根据与一个列表匹配的条件修改两个列表,您可以执行以下操作</p>
<pre><code>mylist = ["hello there", "Watermelons are delicious", "What is the colour of my shirt"]
newlist = []
otherlist = ["1", "2", "3"]
for item in mylist:
if "is the color of" in item:
otherlist.pop(mylist.index(item));
continue;
else:
newlist.append(item)
</code></pre>