How to convert a list of keys and values to dictionary in Python

1 Answer

0 votes
lstKeys = ['a', 'b', 'c', 'd'] 
lstValues = ['python', 'java', 'php', 'c++']

dic = {lstKeys[i]: lstValues[i] for i in range(0, len(lstKeys), 1)} 

print(dic) 


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

'''

 



answered Jan 11, 2021 by avibootz
...