users = {'sam': 20, 'mike': 30, 'joe': 40}
# return users where the ave is greater than 20
users_over_20 = {k: v for k, v in users.items() if v > 20}
# print users over 20
print(users_over_20)
# output {'mike': 30, 'joe': 40}
# Dictionary Comprehension Types
{j:j*2 for i in range(10)}
#using if
{j:j*2 for j in range(10) if j%2==0}
#using if and
{j:j*2 for j in range(10) if j%2==0 and j%3==0}
#using if else
{j:(j*2 if j%2==0 and j%3==0 else 'invalid' )for j in range(10) }
# dict comprehension we use same logic, with a difference of key:value pair
# {key:value for i in list}
fruits = ["apple", "banana", "cherry"]
print({f: len(f) for f in fruits})
#output
{'apple': 5, 'banana': 6, 'cherry': 6}