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
string
NoneType
List comprehension, as other answers proposed or, for the sake of completeness:
clean = filter(lambda x: x is not None, lis)
If the list is huge, an iterator approach is superior:
from itertools import ifilter clean = ifilter(lambda x: x is not None, lis)