count列表python中的出现次数

时间:2014-11-04 17:55:42

标签: python

我有一个包含列表中存在的所有可能值的集合。我想知道的是知道列表中存在多少值。

所以,我有:

set_a = ("a","b", "c", "d")
lst = ["a", "b", "c", "c"]

我想要的是:

a 1
b 1
c 2

1 个答案:

答案 0 :(得分:0)

您将在此处看到解决方案:How can I count the occurrences of a list item in Python?

例如,你可以这样做:

[1, 2, 3, 4, 1, 4, 1].count(1)