Reputation: 3
For example there is a list like A = [7 , 77 , 777 , 717]
. I want to count the number of occurrences of the digit 7
in the list, but without using any loops. It should output 8
. (7
occurred 8
times). Does anyone know how to do this? I tried to do it by loops but couldn't find a way to do it without any loops (if it's even possible).
Upvotes: -4
Views: 109
Reputation: 27800
One way is to just convert it into string and count
A = [7 , 77 , 777 , 717]
str(A).count('7')
#output
8
Upvotes: 8