Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,938 questions

51,875 answers

573 users

How to convert lists into dictionary in Python

3 Answers

0 votes
lst1 = ["python", "java", "c#", "c++", "php"]
lst2 = [10, 13, 7, 5, 21]

zp = zip(lst2, lst1)

dic = list(zp)

print(dic)


'''
run:
 
[(10, 'python'), (13, 'java'), (7, 'c#'), (5, 'c++'), (21, 'php')]

'''

 



answered Dec 8, 2017 by avibootz
0 votes
lst1 = ["python", "java", "c#", "c++", "php"]
lst2 = [10, 13, 7, 5, 21, 76, 99, 1003]

dic = dict(zip(lst2, lst1))

print(dic)


'''
run:
 
{10: 'python', 21: 'php', 5: 'c++', 13: 'java', 7: 'c#'}

'''

 



answered Dec 8, 2017 by avibootz
0 votes
dic = dict(list(zip([10, 13, 7, 5, 21, 99], ["python", "java", "c#", "c++", "php"])))

print(dic)


'''
run:
 
{10: 'python', 21: 'php', 5: 'c++', 13: 'java', 7: 'c#'}

'''

 



answered Dec 8, 2017 by avibootz

Related questions

...