You could just use count
method of list
,
>>> n
[0, 1, 0, 2, 2, 0, 0]
>>> elm = 2
>>> print("There are {} {} in {}".format(n.count(elm), elm, n))
There are 2 2 in [0, 1, 0, 2, 2, 0, 0]
or just count it manually if you can’t use any method of list
like count
,
>>> print("There are {} {:d} in {}".format(len([1 for x in n if x == elm]), elm, n))
There are 2 2 in [0, 1, 0, 2, 2, 0, 0]