Python: Convert list to dictionary with indexes as values

后端 未结 5 1963
傲寒
傲寒 2020-12-02 16:08

I am trying to convert the following list:

list = [\'A\',\'B\',\'C\']

To a dictionary like:

dict = {\'A\':0, \'B\':1, \'C\'         


        
5条回答
  •  执笔经年
    2020-12-02 16:59

    Use built-in functions dict and zip :

    >>> lst = ['A','B','C']
    >>> dict(zip(lst,range(len(lst))))
    

提交回复
热议问题