Ignoring a value in a list search
<p>I am using lists to store attributes and this problem cropped up when I was searching for equal items:</p>

<pre><code>l = [['a',1,2],['b',1,2],['c',2,3],['d',1,2]]
if [any,1,2] in l:
    print ('blue')
elif [any,2,3] in l:
    print('red')
</code></pre>

<p>desired output</p>

<pre><code>blue
</code></pre>

<p>What I want is the first value being ignored/can be any value.
I know the any function doesn't work this way but what is the correct method to doing so?</p>

<p>Perhaps this is more understandable</p>

<pre><code>l = [['a',1,2],['b',1,2],['c',2,3],['d',1,2]]
for a in range(0,4):
    if [1,2] == x[1:] for x in l:
        print ('blue')
    elif [2,3] == x[1:] for x in l:
        print('red')
</code></pre>

<p>:D actually managed to do it in one line thanks to pkacprzak.</p>

<pre><code>l = [['a',1,2],['b',1,2],['c',2,3],['d',1,2]]
if any(True for x in l if x[1:] == [1,2]):
    print ('blue')
elif any(True for x in l if x[1:] == [2,3]):
    print('red')
</code></pre>

<p>Code works like this:</p>

<pre><code>True for x in l
</code></pre>

<p>iterates over l (&lt;---this is the letter L btw) and returns True if the next bit is True</p>

<pre><code>if x[1:] == [1,2]
</code></pre>

<p>this checks all values of x except the first and returns True</p>

<pre><code>any(...)
</code></pre>

<p>finds if any of the values returned from the bit inside the any is True</p>

<p>You could also return the value of the first item like so</p>

<pre><code>[x[0] for x in l if x[1:] == [1,2]]
</code></pre>

<p>and iterate over that as well</p>

python list