Py学习  »  Python

如何在python 3中从嵌套列表中删除多个项?

pycoderr • 5 年前 • 1539 次点击  

如何在不使用列表理解的情况下从python 3的嵌套列表中删除多个项?有时 Indexerror 是怎么处理的?

split_list =[["a","b","c"],["SUB","d","e",],["f","Billing"]]
rem_word = ['SUB', 'Billing', 'Independent', 'DR']
for sub_list in split_list:
  for sub_itm in sub_list:
    if sub_itm not in rem_word:
        print(sub_itm)

输出如下:

 a
 b
 c
 d
 e
 f

预期产量:

split_list =[["a","b","c"],["d","e",],["f"]]
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/48395
 
1539 次点击  
文章 [ 3 ]  |  最新文章 5 年前