擅长:python、mysql、java
<p>不要试图修改正在迭代的列表;这会破坏迭代器。相反,构建并返回新列表。在</p>
<pre><code>import json
def check_json (list_of_items, list_of_labels):
new_items = []
new_labels = []
for item, label in zip(list_of items, list_of_labels):
try:
json.loads(item)
except ValueError:
continue
new_items.append(item)
new_labels.append(label)
return new_items, new_labels
</code></pre>
<p>如果您坚持修改原始参数:</p>
^{pr2}$
<p>但请注意,这并没有真正提高效率;它只是提供了一个不同的接口。在</p>