DEV Community

Njeri Kimaru
Njeri Kimaru

Posted on

Turning Two Lists into a Dictionary Using Comprehension

Ever had two lists — one with keys and one with values — and wondered how to merge them into a dictionary? The elegant way to do it is with dictionary comprehension.

Let’s say you have:


python
keys = ['name', 'age', 'city']
values = ['Alice', 25, 'Nairobi']
Enter fullscreen mode Exit fullscreen mode

Top comments (0)