DEV Community

Cover image for List to Dict
Mangabo Kolawole
Mangabo Kolawole Subscriber

Posted on

5 3

List to Dict

Convert lists into dicts using just one line of code.

This trick is useful on a real project with Django and Machine learning for example.

fruits = ["mango", "banana", "apple"]

price = [10, 5, 4]

new_dict = dict(zip(fruits, price))
Enter fullscreen mode Exit fullscreen mode

You can learn more about the zip function here.

Article posted using bloggu.io. Try it for free.

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post