Convert list to dictionary with indexes

less than 1 minute read

Convert list to dictionary with indexes

>>> lst = ['A','B','C']
>>> {k: v for v, k in enumerate(lst)}
{'A': 0, 'C': 2, 'B': 1}

Source

Leave a comment