Nick Coghlan added the comment:

It's a direct counterpart to any() and all() - first([0, [], ()]) is None for 
the same reason that any([0, [], ()]) and all([0, [], ()]) are both False.

If first returned the actual first item in the iterable (regardless of truth 
value), then it would just be "next" under a different name, which would be 
rather pointless.

That said, if "first" is deemed too ambiguous, then I believe "filterednext" 
would be a reasonable more explicit name:

>>> filterednext([0, None, False, [], (), 42])
42

>>> filterednext([0, None, False, [], ()], default=42)
42

>>> filterednext([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0)
4

>>> m = filterednext(regexp.match('abc') for regexp in [re1, re2])

I also believe itertools would be a more appropriate initial home than the 
builtins.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18652>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to