Tuesday, May 5, 2009

Python: convert a list to a dictionary

Give a one line Python code to convert a list such as L=['A','B','C'] to a dictionary indexed by the numeric index 0, 1, 2, e.g., {0: 'A', 1: 'B', 2: 'C'}

1 comment:

Kundan said...

dict(zip(xrange(len(L)), L)))