python remove empty values from list

def compact(lst):
    return list(filter(None, lst))

compact([0, 1, False, 2, '', 3, 'a', 's', 34])     # [ 1, 2, 3, 'a', 's', 34 ]

Here is what the above code is Doing:
1. The filter function takes a function and a list as arguments. The function is called with all the items in the list, and filter returns only those items for which the function returned True.
2. The function passed to filter must return a Boolean value, i.e. either True or False.
3. In the above code, the function is just the identity function, which returns whatever is passed to it. Therefore, all the values for which the identity function returns a True value are returned by filter.
4. Since 0, False, ”, and None are all considered false values in a Boolean context, they are all filtered out.