获取列表元素的数量

Ash*_*tra -6 python list counting

比方说,我有很多名单保存在一个大清单中A.

A=[[1,2], [2,1], [3,1], [1,2]]
Run Code Online (Sandbox Code Playgroud)

如何对此列表进行排序并获取其中每个元素的计数?

编辑:我能想到的唯一方法是获取列表中的每个元素,通过选择较大列表的元素进一步读取列表中的各个元素.

Inb*_*ose 6

使用计数器.

from collections import Counter

A = [[1,2], [2,1], [3,1], [1,2]]
print Counter(tuple(i) for i in A)

>>> 
Counter({(1, 2): 2, (3, 1): 1, (2, 1): 1})
Run Code Online (Sandbox Code Playgroud)