1simple_dict = {
2 'a': 1,
3 'b': 2
4}
5my_dict = {key: value**2 for key,value in simple_dict.items()}
6print(my_dict)
7#result = {'a': 1, 'b': 4}
1# dict comprehension we use same logic, with a difference of key:value pair
2# {key:value for i in list}
3
4fruits = ["apple", "banana", "cherry"]
5print({f: len(f) for f in fruits})
6
7#output
8{'apple': 5, 'banana': 6, 'cherry': 6}
1dict1 = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
2# Double each value in the dictionary
3double_dict1 = {k:v*2 for (k,v) in dict1.items()}
4# double_dict1 = {'e': 10, 'a': 2, 'c': 6, 'b': 4, 'd': 8} <-- new dict