[Python-ideas] Aid reiteration with new class: gfic
John Graham
john.a.graham at gmail.com
Fri Jun 19 21:23:55 CEST 2009
Terry Reedy wrote:
> yoav glazner wrote:
>>
>> On Fri, Jun 19, 2009 at 6:11 AM, Steven D'Aprano <steve at pearwood.info
>> <mailto:steve at pearwood.info>> wrote:
>>
>> On Fri, 19 Jun 2009 07:02:12 am Terry Reedy wrote:
>>
>> As I see it, the correct solution for "my function needs to
>> iterate over
>> an iterable twice" is not to expect the caller to pass a
>> sequence, but
>> to convert the iterable to a sequence inside your function:
>>
>> def function(iterable):
>> # Iterate over iterable twice
>> L = list(iterable)
>> for _ in (1, 2):
>> for x in L:
>> pass
>>
>>
>> As I see it the correct solution is
>> def function(iterable):
>> # Iterate over iterable twice
>> L = iterable.clone() #can be done?
>
> For non-iterator iterables, it is not necessary.
> For iterators in general, it is difficult at best.
> For iterators returned by a constructor, it should be much easier to
> re-call the constructor.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
Exactly how does itertools.tee not cover this use case?
-John Graham
More information about the Python-ideas
mailing list