Iterators membership testing
Mark Lawrence
breamoreboy at yahoo.co.uk
Sun Aug 9 09:45:20 EDT 2015
On 09/08/2015 14:11, Chris Angelico wrote:
> On Sun, Aug 9, 2015 at 11:09 PM, Tim Chase <tim at thechases.com> wrote:
>> On 2015-08-09 19:24, Chris Angelico wrote:
>>> That's exactly right. The only way for the interpreter to handle
>>> 'in' on an iterator is something like this:
>>>
>>> def contains(iter, obj):
>>> for val in iter:
>>> if val == obj: return True
>>> return False
>>
>> Which can nicely be written as
>>
>> any(i == obj for obj in iter)
>
> Indeed it can, although I'm not sure whether it'd just have been
> another step in the explanation :) Whether or not that makes perfect
> sense depends on the reader.
>
> ChrisA
>
This one probably won't make make sense to most readers.
any("Australian batsmen scored any() runs recently?")
See also
http://www.cricketcountry.com/photos/photo-england-supporters-sell-hardly-used-australian-bats-314378
:)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list