Alternative for 'in' operator for nested lists

in-operator, nested-lists, python

Solution

You probably want `any`:

>>> list = [('foo', 'bar'), ('bar', 'foo')]
>>> any('foo' in e for e in list)
True

Some sort of loop is inevitable though.

Problem

If I want to find something in a list in python I can use the 'in' operator: ``` list = ['foo', 'bar'] 'foo' in list #returns True ``` But what should I do if I want to find something in a nested list? ``` list = [('foo', 'bar'), ('bar', 'foo')] 'foo' in list #returns False ``` Is it possible to do it in one row without a for loop for example? Thanks!

Original source