[Python-ideas] Aid reiteration with new class: gfic
Terry Reedy
tjreedy at udel.edu
Fri Jun 19 17:27:52 CEST 2009
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.
More information about the Python-ideas
mailing list