擅长:python、mysql、java
<p>好的,我借用了@Ajax1234提供的代码,并对其进行了修改,使其适用于我的应用程序。你知道吗</p>
<p>他的解决方案几乎是完美的,只是没有改变每个人的名单。我添加了代码来遍历包含列表中的每个列表,并从每个列表中删除“orange”。你知道吗</p>
<p>@John Dengis从一开始就有,但我想提供代码。你知道吗</p>
<p>这是密码。你知道吗</p>
<pre><code>list_of_fruits = ["apple", "banana", "orange"]
list_of_orange_things = ["carrot", "orange", "basketball"]
list_of_colors = ["orange", "green", "blue"]
new_list = [list_of_fruits, list_of_orange_things, list_of_colors]
for lists in new_list:
for item in lists:
if item == "orange":
lists.remove(item)
</code></pre>
<p>没有错误,当我向程序中添加或删除列表时,它会动态调整。你知道吗</p>
<p>正如@johndengis指出的,这是一个遍历列表中的列表的问题。这里有一个问题得到了非常相似的回答:<a href="https://stackoverflow.com/questions/6340351/python-iterating-through-list-of-list">Python - Iterating through list of list</a></p>