On Wed, Dec 10, 2014 at 1:21 AM, Peter Otten <__pete...@web.de> wrote:
>
> Ian Kelly wrote:
> > Huh, I wasn't even aware that membership tests worked on iterables with
no
> > __contains__ method. Seems odd to me that 'x in y' should be supported
but
> > not 'len(y)'.
>
> To me
>
> def contains(iterable, value):
>     for item in iterable:
>         if item == value:
>             return True
>     return False
>
> seems to be a perfectly natural default behaviour. I don't see why
>
> >>> 42 in itertools.count()
> True
>
> should require that len(count()) must succeed.

This also seems perfectly natural:

def len(iterable):
    return sum(1 for item in iterable)

My observation is that seems strange to me that one standard sequence
operation should be supported for arbitrary iterators and the other not.

If the objection about `len(count())` is that the call would never return,
I'll point out that `-42 in count()` suffers the same problem.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to