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

...