How to count how many times a value is in a list using sequence operator as function in Python

1 Answer

0 votes
from operator import *     

a = [3, 3, 1, 3, 2, 3, 4, 6, 3]     
b = ['a', 'b', 'a', 'c', 'a']
c = ['php', 'python', 'php', 'java']

print(countOf(a, 3))
print(countOf(b, 'a'))
print(countOf(c, 'php'))


'''
run:

5
3
2

'''

 



answered May 31, 2019 by avibootz
...