DEV Community

Cover image for List to Dict
Mangabo Kolawole
Mangabo Kolawole

Posted on

 

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)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git