Guido van Rossum wrote:
> I would need to think more about this. I'm tempted not to do this, and
> let these ABCs denote the *explicit* presence of __contains__ and
> __iter__, respectively. Something that's iterable but doesn't
> implement __contains__ supports the 'in' operator very inefficiently
> (through linear search) which we might not want to encourage.
I think a bigger conceptual problem with doing containment tests on
arbitrary iterables is that you may end up consuming an iterator in the
process of checking whether it contains the item you want (i.e. if
Iterable defines __contains__, then Iterator will acquire it by
inheritance).
So "assert (x in obj) == (x in obj)" may well fail in some cases if we
adopt the idea that being iterable implies support for containment tests.
Random thought inspired by the __contains__ code in Raymond's post: does
anyone else think a 'key' parameter on any() and all() would be useful?
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com