Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.

aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

BlueHost Web Hosting Black Friday
BlueHost Web Hosting Black Friday

Bonsai Boy of New York Bonsai Trees and Accessories

DreamCloud The Comfortable Luxury Mattress Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

16,311 questions

21,782 answers

573 users

How to convert a list of tuples into a dictionary with Python

3 Answers

0 votes
def Convert(tmp, dic): 
    dic = dict(tpl) 
    
    return dic 
      
  
tpl = [("aaa", 1), ("bbb", 2), ("ccc", 3), ("ddd", 4), ("eee", 5)] 

dic = {} 

print(Convert(tpl, dic)) 



'''
run:

{'aaa': 1, 'bbb': 2, 'ccc': 3, 'ddd': 4, 'eee': 5}

'''

 




answered Dec 15, 2019 by avibootz
0 votes
tpl = [("aaa", 1), ("bbb", 2), ("ccc", 3), ("ddd", 4), ("eee", 5)] 
 
dic = dict(tpl)

 
print(dic)
 
 
 
'''
run:
 
{'aaa': 1, 'bbb': 2, 'ccc': 3, 'ddd': 4, 'eee': 5}
 
'''

 




answered Jan 29, 2020 by avibootz
0 votes
lst_tpl =  [('a', 'python'), ('b', 'c#'), ('c', 'php'), ('d', 'c++')] 
  
dic =  {lst_tpl[i][0]: lst_tpl[i][1] for i in range(0, len(lst_tpl), 1)} 
 
  
print(dic)
  


     
 
'''
run:
 
{'a': 'python', 'b': 'java', 'c': 'php', 'd': 'c++'}

'''

 




answered 6 days ago by avibootz
...