[Python-ideas] Aid reiteration with new class: gfic
yoav glazner
yoavglazner at gmail.com
Fri Jun 19 16:28:54 CEST 2009
On Fri, Jun 19, 2009 at 6:11 AM, Steven D'Aprano <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 x in L:
pass
for x in iterable :
pass
this way i avoid endless iterators...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090619/53064da7/attachment.html>
More information about the Python-ideas
mailing list