The number of occurrences of elements in the python List count() method list

count() counts the number of times an element appears in the list

list.count(obj)
testlist = [123, 'abc', 'cdf', 'abc', 123, 123]

print("Count for 123 : ", testlist.count(123)) 
print("Count for abc : ", testlist.count('abc'))

result

Count for 123 :  3
Count for abc :  2

Guess you like

Origin blog.csdn.net/stellao_o/article/details/122935365