advanced dictionary comprehension python code example
Example 1: dict comprehension python
# 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}
Example 2: dict comprehension
# Dictionary comprehension
{i:i*2 for i in range(10)}