I have a list that contains nested lists and I need to know the most efficient way to search within those nested lists.
e.g., if I have
[['a','b','c'],
['d','e','f']]
and I have to search the entire list above, what is the most efficient way to find ‘d’?
Using list comprehension, given:
yields:
and this could also be done with a generator (as shown by @AshwiniChaudhary)
Update based on comment below:
Here is the same list comprehension, but using more descriptive variable names:
The looping constructs in the list comprehension part is equivalent to
and generates a list that where ‘d’ can be tested against with the
inoperator.