list to dict python

Do you want to know the details regarding “list to dict python”. If yes, you’re in the correct article.

list to dict python

my_list = ['Nagendra','Babu','Nitesh','Sathya']
my_dict = dict() 
for index,value in enumerate(my_list):
  my_dict[index] = value
print(my_dict)
#OUTPUT
0: 'Nagendra', 1: 'Babu', 2: 'Nitesh', 3: 'Sathya'
list1 = ['1', '2', '3']
str1 = ''.join(list1)
for key, value in dict.iteritems():
    temp = [key,value]
    dictlist.append(temp)
#This is to convert two lists into a dictionary in Python

#given ListA is key
#given ListB is value

listA = ['itemA','itemB']
listB = ['priceA','priceB']
dict(zip(listA, listB))

# Returns 
'itemA': 'priceA',
 'itemB': 'priceB'
dict.items()
from collections import OrderedDict

o = collections.OrderedDict()
for i in data:
     o.setdefault(i[0], []).append(i[1])

Conclusion

I hope this post helps you to know about “list to dict python”. If you have any doubts regarding this article please let us know via the comment section. Share this post with your friends & family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment