📌  相关文章
📜  计算一个值在 python 列表中显示的次数 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:20.437000             🧑  作者: Mango

代码示例1
#use count():
>>> my_list = [1, 2, 3, 1, 4]
>>> print(my_list.count(1))
2

#OR, you can also use counter:
>>> from collections import Counter
>>> z = ['blue', 'red', 'blue', 'yellow', 'blue', 'red']
>>> Counter(z)
Counter({'blue': 3, 'red': 2, 'yellow': 1})