[Python-ideas] Function to return first(or last) true value from list
Ryan Gonzalez
rymg19 at gmail.com
Wed Feb 19 00:30:29 CET 2014
Sorry! I was Googling it, but I must have missed that bug report.
On Tue, Feb 18, 2014 at 4:42 PM, Tim Peters <tim.peters at gmail.com> wrote:
> [Ryan Gonzalez <rymg19 at gmail.com>]
> > It isn't uncommon to try and get either the first or the last True value
> > from a list. In Python 2, you'd do this:
> >
> > next((x for x in mylist if x))
> >
> > And, in Python 3, thanks to filter returning an iterator, you'd do this:
> >
> > next(filter(bool,mylist))
> > ...
>
> See here:
>
> http://bugs.python.org/issue18652
>
> Never heard anyone ask for "last" before "first" has been available
> in a PyPI package for over a year. Detail in the bug report.
>
--
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple:
"It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
nul-terminated."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140218/6b8dcc4e/attachment-0001.html>
More information about the Python-ideas
mailing list