如何将列表转换为字典

时间:2012-12-02 20:01:22

标签: python-3.x

如果我有

a = [['a','b','c'],['b','c','d'],['a','b','c'],['e','f','g'],['b','c','d']]

我如何获得

a = {('a','b','c'):2,('b','c','d'):2,('e','f','g'):1}

1 个答案:

答案 0 :(得分:0)

您可以使用Counter

from collections import Counter

a = Counter(map(tuple, a))