[Tutor] misunderstanding "any"
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 on built-in function any in module __builtin__:
> any(iterable) -> bool
> Return True if bool(x) is True for any x in the iterable.
> 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.
> Mark Lawrence.
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
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?
More information about the Tutor