Python: dictionary comprehensions
Example:
numbers = [1, 2, 3, 4, 5]
Dictionary comprehensions allow the creation of dictionaries using a similar syntax as list comprehensions.
Solution:
squares = {n: n**2 for n in numbers}
Example: Solution:Python: dictionary comprehensions
Dictionary comprehensions allow the creation of dictionaries using a similar syntax as list comprehensions.
numbers = [1, 2, 3, 4, 5]
squares = {n: n**2 for n in numbers}