Before reading this article, please make sure you understand how the lambda function works.
Like zip() and map(), filter can create and return a generator. generator is an implementation of iterator with lazy evaluation features, which can reduce memory usage very effectively.
The filter() function retrieves the desired value from the list and removes the unnecessary value. For example, in the following example we want to find the names of people whose names start with “O” in the list.
names = ['Liam', 'Olivia', 'Noah', 'Emma', 'Oliver', 'Ava']
choice = filter(lambda x: x.startswith('O'), names)
print(*choice, sep=', ') # Olivia, Oliver