Native Python function to remove NoneType elements from list?

后端 未结 5 1813
终归单人心
终归单人心 2020-12-30 20:42

I\'m using Beautiful Soup in Python to scrape some data from HTML files. In some cases, Beautiful Soup returns lists that contain both string and NoneType

5条回答
  •  既然无缘
    2020-12-30 20:52

    I think the cleanest way to do this would be:

    #lis = some list with NoneType's
    filter(None, lis)
    

提交回复
热议问题