Programming tricks related to ActionScript, Python, C/C++ and Java. See the comments for answers.
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:
dict(zip(xrange(len(L)), L)))
Post a Comment