This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients hynek, lukasz.langa, ncoghlan, rhettinger, serhiy.storchaka
Date 2013-08-04.10:58:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1375613918.37.0.222692945276.issue18652@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-08-04 10:58:38ncoghlansetrecipients: + ncoghlan, rhettinger, lukasz.langa, hynek, serhiy.storchaka
2013-08-04 10:58:38ncoghlansetmessageid: <1375613918.37.0.222692945276.issue18652@psf.upfronthosting.co.za>
2013-08-04 10:58:38ncoghlanlinkissue18652 messages
2013-08-04 10:58:38ncoghlancreate