python .count for multidimensional arrays (list of lists) -


how count number of occurrences of value in multidimensional array made nested lists? in, when looking 'foobar' in following list:

list = [['foobar', 'a', 'b'], ['x', 'c'], ['y', 'd', 'e', 'foobar'], ['z', 'f']] 

it should return 2.

(yes aware write loop searches through of it, dislike solution rather time-consuming, (to write , during runtime))

.count maybe?

>>> list = [['foobar', 'a', 'b'], ['x', 'c'], ['y', 'd', 'e', 'foobar'], ['z', 'f']] >>> sum(x.count('foobar') x in list) 2 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -