list comprehension in dict python code example
Example 1: dictionary comprehension python
square_dict = {num: num*num for num in range(1, 11)}
Example 2: dictionary comprehension
li = ['The', 'quick', 'brown', 'fox', 'was', 'quick']d = {k:1 for k in li}d #=> {'The': 1, 'quick': 1, 'brown': 1, 'fox': 1, 'was': 1}