For example,
a=[[a, 1], [b, 1], [1, 1]]
I want to find how many "1"s there are, but only those that are the second element in the nested lists. So it should give me 3, ignoring the "1" in the third list as it is the first element in the list.
Use collections.Counter subclass to count occurrences of any value:
import collections
a = [['a', 1], ['b', 1], [1, 1]]
counts = collections.Counter((l[1] for l in a))
print(counts[1]) # 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With