Python Practice › Dictionary Programs › Program 49
Keys a, b, c with ranges
Write a Python program to create {“a”: 1-5, “b”: 6-10, “c”: 11-15} as lists.
Output
{'a': [1, 2, 3, 4, 5], 'b': [6, 7, 8, 9, 10], 'c': [11, 12, 13, 14, 15]}Approach
- Each key’s list starts 5 higher than the previous.
Solution
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]}Learn the concept
New to this topic? Read the lesson, then come back.