python filter None dictionary

d = dict(a = 1, b = None, c = 3)

filtered = dict(filter(lambda item: item[1] is not None, d.items()))

{'a': 1, 'c': 3}

Here is what the above code is Doing:
1. We have a dictionary with three key-value pairs.
2. We use the filter function to filter out the key-value pairs where the value is None.
3. We print the resulting dictionary.

Note that the filter function returns a filter object, which is an iterator. We can convert this iterator to a dictionary using the dict function.