How to convert list to dictionary with index as value in Python

1 Answer

0 votes
lst = ['python', 'c', 'c++', 'java'] 

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

print(dic)
  


     
 
'''
run:
 
{'python': 0, 'c': 1, 'c++': 2, 'java': 3}

'''

 



answered Jan 11, 2021 by avibootz
...