Converting a list to the dictionary
This method is used to convert a python list into a python dictionary with indexes as keys.
Python3
vegetables = [ 'Carrot' , 'Raddish' , 'Brinjal' , 'Potato' ] veg_dict = dict ( enumerate (vegetables)) print (veg_dict) |
Output:
{0: ‘Carrot’, 1: ‘Raddish’, 2: ‘Brinjal’, 3: ‘Potato’}
There are other methods as well to add values to a dictionary but the above-shown methods are some of the most commonly used ones and highly efficient as well.
How to add values to dictionary in Python
In this article, we will learn what are the different ways to add values in a dictionary in Python.
Contact Us