List Comprehension for Dictionaries

Just as we have seen with lists, we can perform comprehension with dictionaries as well.


Example:
Given a dictionary with names and values, let's subset the dictionary to return a dictionary with names that contain the letter 'a' and multiply square the value of their number

sample_dict = {'Joan': 2, 'Leo': 3, 'Jane':4, 'Lexi':5 }

{ name:value**2 for name,value in sample_dict.items() if 'a' in name }
{'Joan': 4, 'Jane': 16}