Python list and dictionary comprehension
问题 I am trying to get use to list dictionaries comprehension. Here a small code I have not been able to transform. lst = ['C', 'A', 'B', 'A'] myd = {} for v, k in enumerate(lst): if k in myd: myd[k].append(v) else: myd[k] = [v] print(myd) >>> {'C': [0], 'A': [1, 3], 'B': [2]} I would be please to have some help. 回答1: Here is the answer, although I think the non comprehension approach is much easier to understand. And as mentioned this is not efficient in the least. I would stay with what you