Native Python function to remove NoneType elements from list?

后端 未结 5 1812
终归单人心
终归单人心 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:53

    You could easily remove all NoneType objects from a list using a list comprehension:

    lis = [i for i in lis if i is not None]
    

提交回复
热议问题