Keys a, b, c with ranges

EasyDictionary Programs · 49 of 94

Write a Python program to create {“a”: 1-5, “b”: 6-10, “c”: 11-15} as lists.

Advertisement
Output
{'a': [1, 2, 3, 4, 5], 'b': [6, 7, 8, 9, 10], 'c': [11, 12, 13, 14, 15]}

Approach

  1. Each key’s list starts 5 higher than the previous.

Solution

Python
print({key: list(range(1 + 5 * i, 6 + 5 * i)) for i, key in enumerate("abc")})
Output
{'a': [1, 2, 3, 4, 5], 'b': [6, 7, 8, 9, 10], 'c': [11, 12, 13, 14, 15]}
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs