Contact: aviboots(AT)netvision.net.il
39,926 questions
51,859 answers
573 users
import itertools, collections nestedlist = [[1, 2, 3], [1, 5], [6, 1, 8, 9, 10], [1, 9, 10, 10], [1]] N = 1 countN = collections.Counter(itertools.chain(*nestedlist)) print(countN[N]) ''' run: 5 '''
nestedlist = [[1, 2, 3], [1, 5], [6, 1, 8, 9, 10], [1, 9, 10, 10], [1]] N = 1 countN = sum(x.count(N) for x in nestedlist) print(countN) ''' run: 5 '''