[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-ideas
Subject:    Re: [Python-ideas] Function to return first(or last) true value from list
From:       Chris Angelico <rosuav () gmail ! com>
Date:       2014-02-22 17:00:59
Message-ID: CAPTjJmoEp=mDua-hMGwUGRh4TLeG-Gvr81r7ZoK=hmnZGrODcA () mail ! gmail ! com
[Download RAW message or body]

On Sun, Feb 23, 2014 at 3:52 AM, אלעזר <elazarg@gmail.com> wrote:
> If an iterators were indexable, with non-decreasing order only, then
> first(it) would become a simple it[0]. with exactly the same semantics,
> except the possibilty of raising a (visible) IndexError on an exhausted
> iterator, instead of .
>
> By "non decreasing" I mean the ability to do something like this:
>
>     it = iter('abcd')
>     for i in range(4):
>         print(it[i])
>
> Of course, it will force the iterator to have additional memory.
> I am sure this was suggested before, probably many times (and obviously
> rejected), but not exactly in this specific context.
> So, maybe allowing only it[0], or maybe generator[0], would be nice (even if
> it's just an ugly special case").

You can get that with itertools.tee(), or list().

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic