Say I have a 2-dimensional array of strings like so:
A = [['a', 'b', 'b'],
['c', 'c', 'a'],
['d', 'c', 'a']]
and I want to find out how many rows a given element appears in, so that I get the output:
In [1]: get_number_rows('a')
Out[1]: 3
In [2]: get_number_rows('b')
Out[2]: 1
In [1]: get_number_rows('c')
Out[1]: 2
In [2]: get_number_rows('d')
Out[2]: 1
Note that I don't want the total number of occurrences of 'a', but the number of rows it appears in.
I have tried looping over the rows and simply counting, but I'm dealing with a very large dataset (1000s x 1000s), so it's very slow. Any faster solutions would be appreciated.