# [Tutor] misunderstanding "any"

col speed ajarncolin at gmail.com
Wed Mar 7 05:36:49 CET 2012

```On 7 March 2012 10:45, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
> On 07/03/2012 03:24, col speed wrote:
>>
>> Hello again
>> Hope you are all well.
>>
>> I'm trying to make a "match 3" game, where you have a square grid and
>> have to put 3 matching shapes in a row.
>> I need a function that tells me if the game is playable, ie. it is
>> possible to match 3 shapes by only swapping 2 adjacent shapes.
>> I have looked at the co-ordinates and got a list of the "offset
>> co-ordinates" needed for the above.
>>
>> I have a list of coordinates and a list of "lemons" and I want to see
>> if *any* lemon coordinate is in the list of coordinates.
>> I tried this:
>> if any(((x+1, y+1), (x-1, y+2),(x-2, y+1),(x-1, y-1 ))) in fruit_type:
>>                     return True
>>
>> Thinking that if  *any* of the tuples is in fruit_type(a list of
>> tuples), then it should return True.
>> However, it always equates to False.
>>
>
>
> Here's the way to find out.
>
>>>> help(any)
> Help on built-in function any in module __builtin__:
>
> any(...)
>    any(iterable) -> bool
>
>    Return True if bool(x) is True for any x in the iterable.
>
>>>> help('in')
> Comparisons
> ***********
>
> [snipped]
>
>
>
> For the list and tuple types, ``x in y`` is true if and only if there
> exists an index *i* such that ``x == y[i]`` is true.
>
>
> [snipped]
>
> --
> Cheers.
>
> Mark Lawrence.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
Thanks Mark
I looked up help(any), but not help(in)!

I *think* I understand:
Where it says:
"For the list and tuple types, ``x in y`` is true if and only if there
> exists an index *i* such that ``x == y[i]`` is true."

I suppose I am looking for .....an index *i* and *j* such that x[j] == y[i].

Is that right?
cheers
Col
```