[Python-ideas] Introduce collections.Reiterable
Neil Girdhar
mistersheik at gmail.com
Thu Sep 19 11:25:08 CEST 2013
Note that neither a generator expression, nor a dictionary view, nor a list
are Iterators. They are all Iterable. The list is also a Sequence. The
Reiterable category applies to the latter two, since they can be iterated
over multiple times without being consume,
On Thu, Sep 19, 2013 at 5:23 AM, Neil Girdhar <mistersheik at gmail.com> wrote:
> No, not things which are iterable but not iterators, things which are
> *reiterable* rather than merely iterable. That is, things that can be
> iterated multiple times without the generated elements disappearing.
>
>
> On Thu, Sep 19, 2013 at 5:20 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>
>>
>> On 19 Sep 2013 19:14, "Neil Girdhar" <mistersheik at gmail.com> wrote:
>> >
>> > I am proposing a new class "Reiterable" that is a subclass of Iterable.
>> For example, a dictionary view is a reiterable. It would be fine to pass
>> such an object to the function f.
>>
>> I'm afraid simply repeating your proposal still doesn't answer my
>> question. You have indicated that you are trying to identify things that
>> are iterable, but not iterators. That is already possible using a second
>> isinstance check to exclude iterators.
>>
>> So, what is the value you see in adding a new ABC to further simplify an
>> already simple check?
>>
>> Cheers,
>> Nick.
>>
>> >
>> > Best,
>> > Neil
>> >
>> >
>> > On Thu, Sep 19, 2013 at 5:12 AM, Nick Coghlan <ncoghlan at gmail.com>
>> wrote:
>> >>
>> >>
>> >> On 19 Sep 2013 18:59, "Neil Girdhar" <mistersheik at gmail.com> wrote:
>> >> >
>> >> > Well, generators are iterable, but if you write a function like:
>> >> >
>> >> > def f(s):
>> >> > for x in s:
>> >> > do_something(x)
>> >> > for x in s:
>> >> > do_something_else(x)
>> >> >
>> >> > x should not be a generator. I am proposing adding a function to
>> itertools like auto_reiterable that would take s and give you an reiterable
>> in the most efficient way possible.
>> >>
>> >> Generators *are* iterators, though, so they fail the second half of
>> the check. Hence my question - is there any obvious case where "iterable
>> but not an iterator" gives the wrong answer?
>> >>
>> >> Cheers,
>> >> Nick.
>> >>
>> >> >
>> >> >
>> >> > On Thu, Sep 19, 2013 at 4:32 AM, Nick Coghlan <ncoghlan at gmail.com>
>> wrote:
>> >> >>
>> >> >> My question would be, does the new class add anything that isn't
>> >> >
>> >> >
>> >> >
>> >
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130919/6da734d2/attachment.html>
More information about the Python-ideas
mailing list